fix(player): 观看全集进入后自动播放
This commit is contained in:
1 parent
350d16db75
commit
37353dac15
5 files changed
+126
-6
No files matched your search
@@ -13,8 +13,18 @@ class PlaybackCoordinator {
|
||||
Future<bool> _acquire(PlaybackSession session, bool Function() valid) {
|
||||
final result = _handoff.then((_) async {
|
||||
if (!valid()) return false;
|
||||
final previous = _owner;
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-coordinator] phase=acquire '
|
||||
'session=${identityHashCode(session)} owner=${session.owner.name} '
|
||||
'previous=${previous == null ? '-' : identityHashCode(previous)} '
|
||||
'previousOwner=${previous?.owner.name ?? '-'} '
|
||||
'previousLive=${previous?.livePlayerCount ?? 0} '
|
||||
'same=${identical(previous, session)}',
|
||||
);
|
||||
}
|
||||
if (_owner != session) {
|
||||
final previous = _owner;
|
||||
if (previous != null && previous.owner != session.owner) {
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
@@ -31,6 +41,12 @@ class PlaybackCoordinator {
|
||||
if (!valid()) return false;
|
||||
_owner = session;
|
||||
}
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-coordinator] phase=acquired '
|
||||
'session=${identityHashCode(session)} live=${session.livePlayerCount}',
|
||||
);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
_handoff = result.then<void>((_) {});
|
||||
|
||||
@@ -84,6 +84,11 @@ class PlaybackSession extends ChangeNotifier {
|
||||
bool get canAutoAdvance => _mayPlay && !_loading && active != null;
|
||||
bool get isLocked => !canPlay(currentEpisode);
|
||||
String? get error => _error;
|
||||
bool get debugAppResumed => _appResumed;
|
||||
bool get debugRouteVisible => _routeVisible;
|
||||
bool get debugOverlayOpen => _overlayOpen;
|
||||
bool get debugVisible => _visible;
|
||||
bool get debugMayPlay => _mayPlay;
|
||||
// Includes initialization and asynchronous disposal, until native release ends.
|
||||
int get livePlayerCount => _live.length;
|
||||
bool get activeSlotActivated => _active?.activated ?? false;
|
||||
@@ -254,6 +259,16 @@ class PlaybackSession extends ChangeNotifier {
|
||||
bool? userWantsPlay,
|
||||
}) async {
|
||||
if (_closed || index < 0 || index >= episodes.length) return;
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-session] phase=select-enter session=${identityHashCode(this)} '
|
||||
'owner=${owner.name} index=$index user=$_userWantsPlay '
|
||||
'selected=$_selected current=$_currentIndex '
|
||||
'appResumed=$_appResumed routeVisible=$_routeVisible '
|
||||
'overlayOpen=$_overlayOpen visible=$_visible mayPlay=$_mayPlay '
|
||||
'live=${_live.length}',
|
||||
);
|
||||
}
|
||||
// 切换到不同剧集时恢复播放;仍停留在同一集时保留用户暂停。
|
||||
if (userWantsPlay != null) {
|
||||
_userWantsPlay = userWantsPlay;
|
||||
@@ -465,6 +480,22 @@ class PlaybackSession extends ChangeNotifier {
|
||||
Future<void> _applyPlayback(_PlayerSlot slot) async {
|
||||
if (_closed || _active != slot || !slot.activated) return;
|
||||
final shouldPlay = _mayPlay && slot.index == _currentIndex && !isLocked;
|
||||
final video = slot.player is VideoPlayerPort
|
||||
? slot.player as VideoPlayerPort
|
||||
: null;
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-session] phase=apply-playback '
|
||||
'session=${identityHashCode(this)} owner=${owner.name} '
|
||||
'index=${slot.index} shouldPlay=$shouldPlay user=$_userWantsPlay '
|
||||
'appResumed=$_appResumed routeVisible=$_routeVisible '
|
||||
'overlayOpen=$_overlayOpen locked=$isLocked '
|
||||
'player=${identityHashCode(slot.player)} '
|
||||
'controller=${video == null ? '-' : identityHashCode(video.controller)} '
|
||||
'isPlaying=${video?.controller.value.isPlaying ?? '-'} '
|
||||
'slotPlaying=${slot.playing}',
|
||||
);
|
||||
}
|
||||
if (shouldPlay == slot.playing) return;
|
||||
if (shouldPlay) {
|
||||
await slot.player.play();
|
||||
@@ -472,6 +503,15 @@ class PlaybackSession extends ChangeNotifier {
|
||||
await slot.player.pause();
|
||||
}
|
||||
slot.playing = shouldPlay;
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-session] phase=apply-playback-result '
|
||||
'session=${identityHashCode(this)} index=${slot.index} '
|
||||
'shouldPlay=$shouldPlay '
|
||||
'isPlaying=${video?.controller.value.isPlaying ?? '-'} '
|
||||
'slotPlaying=${slot.playing}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _syncPlayback() {
|
||||
|
||||
Reference in new issue
Block a user