From 8394d80fc935fc1ef12e6400547083e979fc7cd1 Mon Sep 17 00:00:00 2001 From: canxin Date: Sat, 11 May 2024 23:45:04 +0800 Subject: [PATCH] [Test] Try fix play not return. [Feat] Add File_op_semaphore. --- lib/page/in_music_album.dart | 1 + lib/page/in_search_music_list.dart | 1 + lib/page/search_page.dart | 1 + lib/util/audio_controller.dart | 6 +++--- rust/src/api/cache.rs | 8 ++++++++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/page/in_music_album.dart b/lib/page/in_music_album.dart index eb8301c..4efe07e 100644 --- a/lib/page/in_music_album.dart +++ b/lib/page/in_music_album.dart @@ -413,6 +413,7 @@ List musicAlbumActionPullDown( cacheFile(file: music.info.artPic!, cachePath: picCachePath); } } + cacheFile(file: musiclist.artPic, cachePath: picCachePath); await globalSqlMusicFactory .createMusicListTable(musicLists: [musiclist]); await globalSqlMusicFactory.insertMusic( diff --git a/lib/page/in_search_music_list.dart b/lib/page/in_search_music_list.dart index d8f2083..d98a869 100644 --- a/lib/page/in_search_music_list.dart +++ b/lib/page/in_search_music_list.dart @@ -415,6 +415,7 @@ List musicListActionPullDown( cacheFile(file: music.info.artPic!, cachePath: picCachePath); } } + cacheFile(file: musiclist.artPic, cachePath: picCachePath); await globalSqlMusicFactory .createMusicListTable(musicLists: [musiclist]); await globalSqlMusicFactory.insertMusic( diff --git a/lib/page/search_page.dart b/lib/page/search_page.dart index 7759c08..e1e02f2 100644 --- a/lib/page/search_page.dart +++ b/lib/page/search_page.dart @@ -389,6 +389,7 @@ List 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()); diff --git a/lib/util/audio_controller.dart b/lib/util/audio_controller.dart index 6296da8..921f8ea 100644 --- a/lib/util/audio_controller.dart +++ b/lib/util/audio_controller.dart @@ -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 newPlayMusics = []; List newAudioSources = []; @@ -295,7 +295,7 @@ class AudioHandler extends GetxController { Future 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"); diff --git a/rust/src/api/cache.rs b/rust/src/api/cache.rs index 831c81a..293a3c3 100644 --- a/rust/src/api/cache.rs +++ b/rust/src/api/cache.rs @@ -7,7 +7,9 @@ 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()) @@ -15,6 +17,7 @@ lazy_static! { ExponentialBackoff::builder().build_with_max_retries(5), )) .build(); + static ref FILE_OP_SEMAPHORE: Arc = Arc::new(Semaphore::new(100)); } // 生成哈希值作为文件名 @@ -31,6 +34,7 @@ pub async fn cache_file( cache_path: &str, filename: Option, ) -> Result { + let _ = FILE_OP_SEMAPHORE.acquire().await?; let filename = match filename { None => gen_hash(file), Some(filename) => filename.to_string(), @@ -68,6 +72,8 @@ pub async fn use_cache_file( cache_path: &str, filename: Option, ) -> Option { + let _ = FILE_OP_SEMAPHORE.acquire().await; + let filename = match filename { None => gen_hash(file), Some(filename) => filename.to_string(), @@ -90,6 +96,8 @@ pub async fn delete_cache_file( cache_path: &str, filename: Option, ) -> Result<(), anyhow::Error> { + let _ = FILE_OP_SEMAPHORE.acquire().await?; + let filename = match filename { None => gen_hash(file), Some(filename) => filename.to_string(),