audio notification

Closes #1635

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-10-19 11:24:14 +08:00
parent 9482a706da
commit 71a170deb5
3 changed files with 60 additions and 5 deletions

View File

@@ -20,6 +20,8 @@ import 'package:PiliPlus/pages/video/controller.dart';
import 'package:PiliPlus/pages/video/introduction/ugc/widgets/triple_mixin.dart'; import 'package:PiliPlus/pages/video/introduction/ugc/widgets/triple_mixin.dart';
import 'package:PiliPlus/pages/video/pay_coins/view.dart'; import 'package:PiliPlus/pages/video/pay_coins/view.dart';
import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart'; import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart';
import 'package:PiliPlus/plugin/pl_player/models/play_status.dart';
import 'package:PiliPlus/services/service_locator.dart';
import 'package:PiliPlus/utils/accounts.dart'; import 'package:PiliPlus/utils/accounts.dart';
import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/global_data.dart'; import 'package:PiliPlus/utils/global_data.dart';
@@ -114,6 +116,22 @@ class AudioController extends GetxController
_queryPlayUrl(); _queryPlayUrl();
} }
}); });
videoPlayerServiceHandler
?..onPlay = onPlay
..onPause = onPause
..onSeek = onSeek;
}
Future<void> onPlay() async {
await player?.play();
}
Future<void> onPause() async {
await player?.pause();
}
Future<void> onSeek(Duration duration) async {
await player?.seek(duration);
} }
void _updateCurrItem(DetailItem item) { void _updateCurrItem(DetailItem item) {
@@ -121,6 +139,11 @@ class AudioController extends GetxController
hasLike.value = item.stat.hasLike_7; hasLike.value = item.stat.hasLike_7;
coinNum.value = item.stat.hasCoin_8 ? 2 : 0; coinNum.value = item.stat.hasCoin_8 ? 2 : 0;
hasFav.value = item.stat.hasFav; hasFav.value = item.stat.hasFav;
videoPlayerServiceHandler?.onVideoDetailChange(
item,
(subId.firstOrNull ?? oid).toInt(),
hashCode.toString(),
);
} }
Future<void> _queryPlayList({ Future<void> _queryPlayList({
@@ -240,20 +263,30 @@ class AudioController extends GetxController
if (position.inSeconds != this.position.value.inSeconds) { if (position.inSeconds != this.position.value.inSeconds) {
this.position.value = position; this.position.value = position;
_videoDetailController?.playedTime = position; _videoDetailController?.playedTime = position;
videoPlayerServiceHandler?.onPositionChange(position);
} }
}), }),
player!.stream.duration.listen((duration) { player!.stream.duration.listen((duration) {
this.duration.value = duration; this.duration.value = duration;
}), }),
player!.stream.playing.listen((playing) { player!.stream.playing.listen((playing) {
PlayerStatus playerStatus;
if (playing) { if (playing) {
animController.forward(); animController.forward();
playerStatus = PlayerStatus.playing;
} else { } else {
animController.reverse(); animController.reverse();
playerStatus = PlayerStatus.paused;
} }
videoPlayerServiceHandler?.onStatusChange(playerStatus, false, false);
}), }),
player!.stream.completed.listen((completed) { player!.stream.completed.listen((completed) {
_videoDetailController?.playedTime = duration.value; _videoDetailController?.playedTime = duration.value;
videoPlayerServiceHandler?.onStatusChange(
PlayerStatus.completed,
false,
false,
);
if (completed) { if (completed) {
switch (playMode.value) { switch (playMode.value) {
case PlayRepeat.pause: case PlayRepeat.pause:
@@ -614,6 +647,11 @@ class AudioController extends GetxController
@override @override
void onClose() { void onClose() {
// _cancelTimer(); // _cancelTimer();
videoPlayerServiceHandler
?..onPlay = null
..onPause = null
..onSeek = null
..onVideoDetailDispose(hashCode.toString());
_subscriptions?.forEach((e) => e.cancel()); _subscriptions?.forEach((e) => e.cancel());
_subscriptions = null; _subscriptions = null;
player?.dispose(); player?.dispose();

View File

@@ -1171,7 +1171,11 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
LongPressGestureRecognizer? _longPressRecognizer; LongPressGestureRecognizer? _longPressRecognizer;
LongPressGestureRecognizer get longPressRecognizer => _longPressRecognizer ??= LongPressGestureRecognizer get longPressRecognizer => _longPressRecognizer ??=
LongPressGestureRecognizer(duration: const Duration(milliseconds: 300)) LongPressGestureRecognizer(
duration: plPlayerController.enableTapDm
? const Duration(milliseconds: 300)
: null,
)
..onLongPressStart = ((_) => ..onLongPressStart = ((_) =>
plPlayerController.setLongPressStatus(true)) plPlayerController.setLongPressStatus(true))
..onLongPressEnd = (_) => plPlayerController.setLongPressStatus(false); ..onLongPressEnd = (_) => plPlayerController.setLongPressStatus(false);
@@ -1318,7 +1322,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
if (!isLive) if (!isLive)
Positioned.fill( Positioned.fill(
top: 4,
child: IgnorePointer( child: IgnorePointer(
ignoring: !plPlayerController.enableDragSubtitle, ignoring: !plPlayerController.enableDragSubtitle,
child: Obx( child: Obx(

View File

@@ -1,4 +1,5 @@
import 'package:PiliPlus/common/constants.dart'; import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/grpc/bilibili/app/listener/v1.pb.dart' show DetailItem;
import 'package:PiliPlus/models_new/live/live_room_info_h5/data.dart'; import 'package:PiliPlus/models_new/live/live_room_info_h5/data.dart';
import 'package:PiliPlus/models_new/pgc/pgc_info_model/episode.dart'; import 'package:PiliPlus/models_new/pgc/pgc_info_model/episode.dart';
import 'package:PiliPlus/models_new/video/video_detail/data.dart'; import 'package:PiliPlus/models_new/video/video_detail/data.dart';
@@ -29,15 +30,19 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
static final List<MediaItem> _item = []; static final List<MediaItem> _item = [];
bool enableBackgroundPlay = Pref.enableBackgroundPlay; bool enableBackgroundPlay = Pref.enableBackgroundPlay;
Function? onPlay;
Function? onPause;
Function(Duration position)? onSeek;
@override @override
Future<void> play() async { Future<void> play() async {
PlPlayerController.playIfExists(); onPlay?.call() ?? PlPlayerController.playIfExists();
// player.play(); // player.play();
} }
@override @override
Future<void> pause() async { Future<void> pause() async {
await PlPlayerController.pauseIfExists(); await (onPause?.call() ?? PlPlayerController.pauseIfExists());
// player.pause(); // player.pause();
} }
@@ -48,7 +53,8 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
updatePosition: position, updatePosition: position,
), ),
); );
await PlPlayerController.seekToIfExists(position, isSeek: false); await (onSeek?.call(position) ??
PlPlayerController.seekToIfExists(position, isSeek: false));
// await player.seekTo(position); // await player.seekTo(position);
} }
@@ -179,6 +185,14 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
duration: Duration(seconds: data.duration ?? 0), duration: Duration(seconds: data.duration ?? 0),
artUri: Uri.parse(cover ?? ''), artUri: Uri.parse(cover ?? ''),
); );
} else if (data is DetailItem) {
mediaItem = MediaItem(
id: id,
title: data.arc.title,
artist: data.owner.name,
duration: Duration(seconds: data.arc.duration.toInt()),
artUri: Uri.parse(data.arc.cover),
);
} }
if (mediaItem == null) return; if (mediaItem == null) return;
// if (kDebugMode) debugPrint("exist: ${PlPlayerController.instanceExists()}"); // if (kDebugMode) debugPrint("exist: ${PlPlayerController.instanceExists()}");