Skip to content

Commit

Permalink
mod: add more setActive
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jul 21, 2024
1 parent 0404e74 commit 0098fcb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/plugin/pl_player/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ class PlPlayerController {
: dataSource.audioSource!.replaceAll(':', '\\:'),
);
}
audioSessionHandler.setActive(true);
await _videoPlayerController!.open(
Media(
dataSource.videoSource!,
Expand Down Expand Up @@ -882,7 +883,7 @@ class PlPlayerController {
/// TODO _duration.value丢失
Future<void> play({bool repeat = false, bool hideControls = true}) async {
if (_playerCount.value == 0) return;
audioSessionHandler.setActive(true);
await audioSessionHandler.setActive(true);
// 播放时自动隐藏控制条
controls = !hideControls;
// repeat为true,将从头播放
Expand All @@ -898,7 +899,6 @@ class PlPlayerController {

playerStatus.status.value = PlayerStatus.playing;
// screenManager.setOverlays(false);

}

/// 暂停播放
Expand Down
4 changes: 3 additions & 1 deletion lib/services/audio_handler.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:PiliPalaX/services/service_locator.dart';
import 'package:audio_service/audio_service.dart';
import 'package:flutter/cupertino.dart';
import 'package:hive/hive.dart';
Expand Down Expand Up @@ -64,14 +65,15 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
// print(newMediaItem);
// print(newMediaItem.title);
// debugPrint(StackTrace.current.toString());
if(!mediaItem.isClosed) mediaItem.add(newMediaItem);
if (!mediaItem.isClosed) mediaItem.add(newMediaItem);
}

Future<void> setPlaybackState(PlayerStatus status, bool isBuffering) async {
if (!enableBackgroundPlay) return;

final AudioProcessingState processingState;
final playing = status == PlayerStatus.playing;
if (playing) audioSessionHandler.setActive(true);
if (status == PlayerStatus.completed) {
processingState = AudioProcessingState.completed;
} else if (isBuffering) {
Expand Down
7 changes: 1 addition & 6 deletions lib/services/audio_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ class AudioSessionHandler {
// player.setVolume(player.volume.value * 2);
break;
case AudioInterruptionType.pause:
if (_playInterrupted && await setActive(true)) {
PlPlayerController.playIfExists();
} else {
SmartDialog.showToast(
'The request was denied and the app should not play audio');
}
if (_playInterrupted) PlPlayerController.playIfExists();
//player.play();
break;
case AudioInterruptionType.unknown:
Expand Down

0 comments on commit 0098fcb

Please sign in to comment.