From cfd2038e3625a14249e0edd0f37b0ae710928baa Mon Sep 17 00:00:00 2001 From: Riri Date: Wed, 25 Oct 2023 20:48:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E5=88=86P=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=AA=92=E4=BD=93=E9=80=9A=E7=9F=A5=E9=94=99=E4=B9=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/services/audio_handler.dart | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/services/audio_handler.dart b/lib/services/audio_handler.dart index 8e4a9ff8..13e9ee51 100644 --- a/lib/services/audio_handler.dart +++ b/lib/services/audio_handler.dart @@ -77,18 +77,31 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler { } onVideoDetailChange(dynamic data, int cid) { + if (data == null) return; Map argMap = Get.arguments; final heroTag = argMap['heroTag']; late MediaItem? mediaItem; if (data is VideoDetailData) { - mediaItem = MediaItem( - id: heroTag, - title: data.title ?? "", - artist: data.owner?.name ?? "", - duration: Duration(seconds: data.duration ?? 0), - artUri: Uri.parse(data.pic ?? ""), - ); + if ((data.pages?.length ?? 0) > 0) { + final current = data.pages?.firstWhere((element) => element.cid == cid); + mediaItem = MediaItem( + id: heroTag, + title: current?.pagePart ?? "", + artist: data.title ?? "", + album: data.title ?? "", + duration: Duration(seconds: current?.duration ?? 0), + artUri: Uri.parse(data.pic ?? ""), + ); + } else { + mediaItem = MediaItem( + id: heroTag, + title: data.title ?? "", + artist: data.owner?.name ?? "", + duration: Duration(seconds: data.duration ?? 0), + artUri: Uri.parse(data.pic ?? ""), + ); + } } else if (data is BangumiInfoModel) { final current = data.episodes?.firstWhere((element) => element.cid == cid); @@ -110,7 +123,6 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler { processingState: AudioProcessingState.idle, playing: false, )); - stop(); _item.removeLast(); if (_item.isNotEmpty) { setMediaItem(_item.last); @@ -118,16 +130,18 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler { if (_item.isEmpty) { playbackState .add(playbackState.value.copyWith(updatePosition: Duration.zero)); + stop(); } } clear() { + mediaItem.add(null); playbackState.add(PlaybackState( processingState: AudioProcessingState.idle, playing: false, )); - mediaItem.add(null); _item.clear(); + stop(); } onPositionChange(Duration position) {