Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions lib/pages/audio/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,14 @@ class AudioController extends GetxController
_queryPlayUrl();
}
});
videoPlayerServiceHandler
?..onPlay = onPlay
..onPause = onPause
..onSeek = onSeek;
final handler = videoPlayerServiceHandler;
if (handler != null) {
handler.onPlay = onPlay;
handler.onPause = onPause;
handler.onSeek = onSeek;
handler.onSkipToPrevious = () async => playPrev();
handler.onSkipToNext = () async => playNext();
}

animController = AnimationController(
vsync: this,
Expand Down Expand Up @@ -780,11 +784,15 @@ class AudioController extends GetxController
..onPause = null
..isPlaying = null
..reset();
videoPlayerServiceHandler
?..onPlay = null
..onPause = null
..onSeek = null
..onVideoDetailDispose(hashCode.toString());
videoPlayerServiceHandler?.onVideoDetailDispose(hashCode.toString());
final handler = videoPlayerServiceHandler;
if (handler != null) {
handler.onPlay = null;
handler.onPause = null;
handler.onSeek = null;
handler.onSkipToPrevious = null;
handler.onSkipToNext = null;
}
_subscriptions?.forEach((e) => e.cancel());
_subscriptions?.clear();
_subscriptions = null;
Expand Down
4 changes: 4 additions & 0 deletions lib/pages/video/introduction/pgc/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class PgcIntroController extends CommonIntroController {

super.onInit();

// 注册播控中心上一集/下一集回调
videoPlayerServiceHandler?.onSkipToPrevious = () async => prevPlay();
videoPlayerServiceHandler?.onSkipToNext = () async => nextPlay();

if (isPgc) {
if (isLogin) {
queryIsFollowed();
Expand Down
4 changes: 4 additions & 0 deletions lib/pages/video/introduction/ugc/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
}

videoDetail.value.title = Get.arguments['title'] ?? '';

// 注册播控中心上一集/下一集回调
videoPlayerServiceHandler?.onSkipToPrevious = () async => prevPlay();
videoPlayerServiceHandler?.onSkipToNext = () async => nextPlay();
}

// 获取视频简介&分p
Expand Down
22 changes: 22 additions & 0 deletions lib/services/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
Future<void>? Function()? onPlay;
Future<void>? Function()? onPause;
Future<void>? Function(Duration position)? onSeek;
Future<bool>? Function()? onSkipToNext;
Future<bool>? Function()? onSkipToPrevious;

@override
Future<void> play() {
Expand Down Expand Up @@ -73,6 +75,16 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
// await player.seekTo(position);
}

@override
Future<void> skipToNext() async {
await onSkipToNext?.call();
}

@override
Future<void> skipToPrevious() async {
await onSkipToPrevious?.call();
}

void setMediaItem(MediaItem newMediaItem) {
if (!enableBackgroundPlay) return;
// if (kDebugMode) {
Expand Down Expand Up @@ -115,7 +127,15 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
MediaControl.rewind.copyWith(
androidIcon: 'drawable/ic_baseline_replay_10_24',
),
if (!isLive)
MediaControl.skipToPrevious.copyWith(
androidIcon: 'drawable/ic_skip_previous',
),
if (playing) MediaControl.pause else MediaControl.play,
if (!isLive)
MediaControl.skipToNext.copyWith(
androidIcon: 'drawable/ic_skip_next',
),
if (!isLive)
MediaControl.fastForward.copyWith(
androidIcon: 'drawable/ic_baseline_forward_10_24',
Expand All @@ -124,6 +144,8 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
playing: playing,
systemActions: const {
MediaAction.seek,
MediaAction.skipToNext,
MediaAction.skipToPrevious,
},
),
);
Expand Down
Loading