From 464ffac0743e7c04a9855bbac2b66ba38ef10b1a Mon Sep 17 00:00:00 2001 From: guozhigq Date: Thu, 7 Mar 2024 23:35:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AA=92=E4=BD=93=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1=E6=9C=AA=E6=8C=89=E9=A2=84=E6=9C=9F?= =?UTF-8?q?=E5=81=9C=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugin/pl_player/controller.dart | 4 +++- lib/services/audio_handler.dart | 7 ++++--- lib/services/audio_session.dart | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index b159163a..f2544f38 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -579,8 +579,10 @@ class PlPlayerController { if (event) { playerStatus.status.value = PlayerStatus.playing; } else { - // playerStatus.status.value = PlayerStatus.paused; + playerStatus.status.value = PlayerStatus.paused; } + videoPlayerServiceHandler.onStatusChange( + playerStatus.status.value, isBuffering.value); /// 触发回调事件 for (var element in _statusListeners) { diff --git a/lib/services/audio_handler.dart b/lib/services/audio_handler.dart index 1f34d21e..08ff3e60 100644 --- a/lib/services/audio_handler.dart +++ b/lib/services/audio_handler.dart @@ -26,6 +26,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler { static final List _item = []; Box setting = GStrorage.setting; bool enableBackgroundPlay = false; + PlPlayerController player = PlPlayerController.getInstance(); VideoPlayerServiceHandler() { revalidateSetting(); @@ -38,12 +39,12 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler { @override Future play() async { - PlPlayerController.getInstance().play(); + player.play(); } @override Future pause() async { - PlPlayerController.getInstance().pause(); + player.pause(); } @override @@ -51,7 +52,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler { playbackState.add(playbackState.value.copyWith( updatePosition: position, )); - await PlPlayerController.getInstance().seekTo(position); + await player.seekTo(position); } Future setMediaItem(MediaItem newMediaItem) async { diff --git a/lib/services/audio_session.dart b/lib/services/audio_session.dart index 49c41906..3f83d320 100644 --- a/lib/services/audio_session.dart +++ b/lib/services/audio_session.dart @@ -20,7 +20,7 @@ class AudioSessionHandler { session.interruptionEventStream.listen((event) { final player = PlPlayerController.getInstance(); if (event.begin) { - if (player.playerStatus != PlayerStatus.playing) return; + if (!player.playerStatus.playing) return; switch (event.type) { case AudioInterruptionType.duck: player.setVolume(player.volume.value * 0.5); @@ -52,7 +52,7 @@ class AudioSessionHandler { // 耳机拔出暂停 session.becomingNoisyEventStream.listen((_) { final player = PlPlayerController.getInstance(); - if (player.playerStatus == PlayerStatus.playing) { + if (player.playerStatus.playing) { player.pause(); } });