Skip to content

Commit

Permalink
[Test] Try fix play not return.
Browse files Browse the repository at this point in the history
[Feat] Add File_op_semaphore.
  • Loading branch information
canxin121 committed May 11, 2024
1 parent c7e6870 commit 8394d80
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/page/in_music_album.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ List<PullDownMenuEntry> musicAlbumActionPullDown(
cacheFile(file: music.info.artPic!, cachePath: picCachePath);
}
}
cacheFile(file: musiclist.artPic, cachePath: picCachePath);
await globalSqlMusicFactory
.createMusicListTable(musicLists: [musiclist]);
await globalSqlMusicFactory.insertMusic(
Expand Down
1 change: 1 addition & 0 deletions lib/page/in_search_music_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ List<PullDownMenuEntry> musicListActionPullDown(
cacheFile(file: music.info.artPic!, cachePath: picCachePath);
}
}
cacheFile(file: musiclist.artPic, cachePath: picCachePath);
await globalSqlMusicFactory
.createMusicListTable(musicLists: [musiclist]);
await globalSqlMusicFactory.insertMusic(
Expand Down
1 change: 1 addition & 0 deletions lib/page/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ List<PullDownMenuEntry> searchMusicListCardPullDown(
cacheFile(file: music.info.artPic!, cachePath: picCachePath);
}
}
cacheFile(file: musiclist.artPic, cachePath: picCachePath);
await globalSqlMusicFactory.insertMusic(
musicList: musiclist,
musics: musics.map((e) => e.ref).toList());
Expand Down
6 changes: 3 additions & 3 deletions lib/util/audio_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ class AudioHandler extends GetxController {
playMusicList.add(firstMusic);
await playSourceList.add(firstMusic.toAudioSource());
updateRx(music: firstMusic);
await seek(Duration.zero, index: 0);
play();

await play();

List<PlayMusic> newPlayMusics = [];
List<AudioSource> newAudioSources = [];
Expand Down Expand Up @@ -295,7 +295,7 @@ class AudioHandler extends GetxController {

Future<void> play() async {
try {
await _player.play();
Future.microtask(() => _player.play());
// talker.info("[Music Handler] In play, succeed");
} catch (e) {
talker.error("[Music Handler] In play. error occur: $e");
Expand Down
8 changes: 8 additions & 0 deletions rust/src/api/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ use lazy_static::lazy_static;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use reqwest_retry::policies::ExponentialBackoff;
use reqwest_retry::RetryTransientMiddleware;
use std::sync::Arc;
use tokio::io::AsyncWriteExt as _;
use tokio::sync::Semaphore;

lazy_static! {
pub static ref CLIENT: ClientWithMiddleware = ClientBuilder::new(reqwest::Client::new())
.with(RetryTransientMiddleware::new_with_policy(
ExponentialBackoff::builder().build_with_max_retries(5),
))
.build();
static ref FILE_OP_SEMAPHORE: Arc<Semaphore> = Arc::new(Semaphore::new(100));
}

// 生成哈希值作为文件名
Expand All @@ -31,6 +34,7 @@ pub async fn cache_file(
cache_path: &str,
filename: Option<String>,
) -> Result<String, anyhow::Error> {
let _ = FILE_OP_SEMAPHORE.acquire().await?;
let filename = match filename {
None => gen_hash(file),
Some(filename) => filename.to_string(),
Expand Down Expand Up @@ -68,6 +72,8 @@ pub async fn use_cache_file(
cache_path: &str,
filename: Option<String>,
) -> Option<String> {
let _ = FILE_OP_SEMAPHORE.acquire().await;

let filename = match filename {
None => gen_hash(file),
Some(filename) => filename.to_string(),
Expand All @@ -90,6 +96,8 @@ pub async fn delete_cache_file(
cache_path: &str,
filename: Option<String>,
) -> Result<(), anyhow::Error> {
let _ = FILE_OP_SEMAPHORE.acquire().await?;

let filename = match filename {
None => gen_hash(file),
Some(filename) => filename.to_string(),
Expand Down

0 comments on commit 8394d80

Please sign in to comment.