Skip to content

Commit

Permalink
fix: 媒体通知进度条未按预期停止
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhigq committed Mar 7, 2024
1 parent ed0b43e commit ab24da5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions lib/plugin/pl_player/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ class PlPlayerController {
danmakuDurationVal =
localCache.get(LocalCacheKey.danmakuDuration, defaultValue: 4.0);
// 描边粗细
strokeWidth =
localCache.get(LocalCacheKey.strokeWidth, defaultValue: 1.5);
strokeWidth = localCache.get(LocalCacheKey.strokeWidth, defaultValue: 1.5);
playRepeat = PlayRepeat.values.toList().firstWhere(
(e) =>
e.value ==
Expand Down Expand Up @@ -535,8 +534,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) {
Expand Down
7 changes: 4 additions & 3 deletions lib/services/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
static final List<MediaItem> _item = [];
Box setting = GStrorage.setting;
bool enableBackgroundPlay = false;
PlPlayerController player = PlPlayerController.getInstance();

VideoPlayerServiceHandler() {
revalidateSetting();
Expand All @@ -38,20 +39,20 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {

@override
Future<void> play() async {
PlPlayerController.getInstance().play();
player.play();
}

@override
Future<void> pause() async {
PlPlayerController.getInstance().pause();
player.pause();
}

@override
Future<void> seek(Duration position) async {
playbackState.add(playbackState.value.copyWith(
updatePosition: position,
));
await PlPlayerController.getInstance().seekTo(position);
await player.seekTo(position);
}

Future<void> setMediaItem(MediaItem newMediaItem) async {
Expand Down
4 changes: 2 additions & 2 deletions lib/services/audio_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -52,7 +52,7 @@ class AudioSessionHandler {
// 耳机拔出暂停
session.becomingNoisyEventStream.listen((_) {
final player = PlPlayerController.getInstance();
if (player.playerStatus == PlayerStatus.playing) {
if (player.playerStatus.playing) {
player.pause();
}
});
Expand Down

0 comments on commit ab24da5

Please sign in to comment.