feat: 修复分P视频媒体通知错乱问题

This commit is contained in:
Riri
2023-10-25 20:48:08 +08:00
parent 79be397f91
commit cfd2038e36

View File

@ -77,11 +77,23 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
} }
onVideoDetailChange(dynamic data, int cid) { onVideoDetailChange(dynamic data, int cid) {
if (data == null) return;
Map argMap = Get.arguments; Map argMap = Get.arguments;
final heroTag = argMap['heroTag']; final heroTag = argMap['heroTag'];
late MediaItem? mediaItem; late MediaItem? mediaItem;
if (data is VideoDetailData) { if (data is VideoDetailData) {
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( mediaItem = MediaItem(
id: heroTag, id: heroTag,
title: data.title ?? "", title: data.title ?? "",
@ -89,6 +101,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
duration: Duration(seconds: data.duration ?? 0), duration: Duration(seconds: data.duration ?? 0),
artUri: Uri.parse(data.pic ?? ""), artUri: Uri.parse(data.pic ?? ""),
); );
}
} else if (data is BangumiInfoModel) { } else if (data is BangumiInfoModel) {
final current = final current =
data.episodes?.firstWhere((element) => element.cid == cid); data.episodes?.firstWhere((element) => element.cid == cid);
@ -110,7 +123,6 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
processingState: AudioProcessingState.idle, processingState: AudioProcessingState.idle,
playing: false, playing: false,
)); ));
stop();
_item.removeLast(); _item.removeLast();
if (_item.isNotEmpty) { if (_item.isNotEmpty) {
setMediaItem(_item.last); setMediaItem(_item.last);
@ -118,16 +130,18 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
if (_item.isEmpty) { if (_item.isEmpty) {
playbackState playbackState
.add(playbackState.value.copyWith(updatePosition: Duration.zero)); .add(playbackState.value.copyWith(updatePosition: Duration.zero));
stop();
} }
} }
clear() { clear() {
mediaItem.add(null);
playbackState.add(PlaybackState( playbackState.add(PlaybackState(
processingState: AudioProcessingState.idle, processingState: AudioProcessingState.idle,
playing: false, playing: false,
)); ));
mediaItem.add(null);
_item.clear(); _item.clear();
stop();
} }
onPositionChange(Duration position) { onPositionChange(Duration position) {