Skip to content

Commit

Permalink
force setMediaItem
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jul 24, 2024
1 parent e04df23 commit dd2c2a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/plugin/pl_player/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ class PlPlayerController {
onPositionChanged.listen((Duration event) {
EasyThrottle.throttle(
'mediaServicePosition',
const Duration(seconds: 1),
const Duration(milliseconds: 200),
() => videoPlayerServiceHandler.onPositionChange(event));
}),
],
Expand Down
20 changes: 12 additions & 8 deletions lib/services/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
Box setting = GStorage.setting;
bool enableBackgroundPlay = true;
// PlPlayerController player = PlPlayerController.getInstance();
MediaItem? _lastMediaItem;

VideoPlayerServiceHandler() {
revalidateSetting();
Expand All @@ -52,12 +53,6 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
// player.pause();
}

seekToNotification(Duration position) {
playbackState.add(playbackState.value.copyWith(
updatePosition: position,
));
}

@override
Future<void> seek(Duration position) async {
SmartDialog.showNotify(
Expand Down Expand Up @@ -113,9 +108,16 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
if (!enableBackgroundPlay) return;

// if (_item.isEmpty) return;
Future.delayed(const Duration(milliseconds: 500), () {
if (_lastMediaItem == null) {
SmartDialog.showToast("当前没有播放内容");
Future.delayed(const Duration(milliseconds: 500), () {
setMediaItem(_lastMediaItem!);
setPlaybackState(status, isBuffering);
});
} else {
setMediaItem(_lastMediaItem!);
setPlaybackState(status, isBuffering);
});
}
}

onVideoDetailChange(dynamic data, int cid) {
Expand Down Expand Up @@ -161,6 +163,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
if (mediaItem == null) return;
// print("exist: ${PlPlayerController.instanceExists()}");
if (!PlPlayerController.instanceExists()) return;
_lastMediaItem = mediaItem;
// _item.add(mediaItem);
setMediaItem(mediaItem);
}
Expand Down Expand Up @@ -201,6 +204,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
onPositionChange(Duration position) {
if (!enableBackgroundPlay) return;

setMediaItem(_lastMediaItem!);
playbackState.add(playbackState.value.copyWith(
updatePosition: position,
));
Expand Down

0 comments on commit dd2c2a2

Please sign in to comment.