diff --git a/lib/pages/live_room/controller.dart b/lib/pages/live_room/controller.dart index 752bbeb00..43a96c154 100644 --- a/lib/pages/live_room/controller.dart +++ b/lib/pages/live_room/controller.dart @@ -184,7 +184,7 @@ class LiveRoomController extends GetxController { final account = Accounts.main; isLogin = account.isLogin; mid = account.mid; - queryLiveUrl(); + queryLiveUrl(autoFullScreenFlag: true); queryLiveInfoH5(); if (Accounts.heartbeat.isLogin && !Pref.historyPause) { VideoHttp.roomEntryAction(roomId: roomId); @@ -194,7 +194,10 @@ class LiveRoomController extends GetxController { } } - Future? playerInit({bool autoplay = true}) { + Future? playerInit({ + bool autoplay = true, + bool autoFullScreenFlag = false, + }) { if (videoUrl == null) { return null; } @@ -203,10 +206,11 @@ class LiveRoomController extends GetxController { isLive: true, autoplay: autoplay, isVertical: isPortrait.value, + autoFullScreenFlag: autoFullScreenFlag, ); } - Future queryLiveUrl() async { + Future queryLiveUrl({bool autoFullScreenFlag = false}) async { currentQn ??= await Utils.isWiFi ? Pref.liveQuality : Pref.liveQualityCellular; @@ -245,7 +249,7 @@ class LiveRoomController extends GetxController { currentQnDesc.value = LiveQuality.fromCode(currentQn)?.desc ?? currentQn.toString(); videoUrl = VideoUtils.getLiveCdnUrl(item); - await playerInit(); + await playerInit(autoFullScreenFlag: autoFullScreenFlag); isLoaded.value = true; } else { _showDialog(res.toString()); diff --git a/lib/pages/live_room/view.dart b/lib/pages/live_room/view.dart index bda5f3dc9..1e395e128 100644 --- a/lib/pages/live_room/view.dart +++ b/lib/pages/live_room/view.dart @@ -75,11 +75,9 @@ class _LiveRoomPageState extends State LiveRoomController(heroTag), tag: heroTag, ); - plPlayerController = _liveRoomController.plPlayerController; - PlPlayerController.setPlayCallBack(plPlayerController.play); - plPlayerController - ..autoEnterFullscreen() + plPlayerController = _liveRoomController.plPlayerController ..addStatusLister(playerListener); + PlPlayerController.setPlayCallBack(plPlayerController.play); } @override diff --git a/lib/pages/video/controller.dart b/lib/pages/video/controller.dart index 52fa69514..850c7cb9f 100644 --- a/lib/pages/video/controller.dart +++ b/lib/pages/video/controller.dart @@ -657,13 +657,13 @@ class VideoDetailController extends GetxController playerInit(); } - Future? _initPlayerIfNeeded() { + Future? _initPlayerIfNeeded(bool autoFullScreenFlag) { if (_autoPlay.value || (plPlayerController.preInitPlayer && !plPlayerController.processing) && (isFileSource ? true : videoPlayerKey.currentState?.mounted == true)) { - return playerInit(); + return playerInit(autoFullScreenFlag: autoFullScreenFlag); } return null; } @@ -675,6 +675,7 @@ class VideoDetailController extends GetxController Duration? duration, bool? autoplay, Volume? volume, + bool autoFullScreenFlag = false, }) async { Duration? seek = seekToTime ?? defaultST ?? playedTime; if (seek == null || seek == Duration.zero) { @@ -715,6 +716,7 @@ class VideoDetailController extends GetxController width: firstVideo.width, height: firstVideo.height, volume: volume ?? this.volume, + autoFullScreenFlag: autoFullScreenFlag, ); if (isClosed) return; @@ -756,9 +758,10 @@ class VideoDetailController extends GetxController Future queryVideoUrl({ Duration? defaultST, bool fromReset = false, + bool autoFullScreenFlag = false, }) async { if (isFileSource) { - return _initPlayerIfNeeded(); + return _initPlayerIfNeeded(autoFullScreenFlag); } if (isQuerying) { return; @@ -832,7 +835,7 @@ class VideoDetailController extends GetxController setVideoHeight(); currentDecodeFormats = VideoDecodeFormatType.fromString('avc1'); currentVideoQa.value = videoQuality; - await _initPlayerIfNeeded(); + await _initPlayerIfNeeded(autoFullScreenFlag); isQuerying = false; return; } @@ -931,7 +934,7 @@ class VideoDetailController extends GetxController } else { audioUrl = ''; } - await _initPlayerIfNeeded(); + await _initPlayerIfNeeded(autoFullScreenFlag); } else { _autoPlay.value = false; videoState.value = result..toast(); diff --git a/lib/pages/video/view.dart b/lib/pages/video/view.dart index df3db77b3..5f822aa19 100644 --- a/lib/pages/video/view.dart +++ b/lib/pages/video/view.dart @@ -162,14 +162,13 @@ class _VideoDetailPageVState extends State } // 获取视频资源,初始化播放器 - Future videoSourceInit() async { - videoDetailController.queryVideoUrl(); + void videoSourceInit() { + videoDetailController.queryVideoUrl(autoFullScreenFlag: true); if (videoDetailController.autoPlay) { plPlayerController = videoDetailController.plPlayerController; plPlayerController! ..addStatusLister(playerListener) ..addPositionListener(positionListener); - await plPlayerController!.autoEnterFullscreen(); } } @@ -295,11 +294,11 @@ class _VideoDetailPageVState extends State } /// 未开启自动播放时触发播放 - Future handlePlay() async { + Future? handlePlay() { if (!videoDetailController.isFileSource) { if (videoDetailController.isQuerying) { if (kDebugMode) debugPrint('handlePlay: querying'); - return; + return null; } if (videoDetailController.videoUrl == null || videoDetailController.audioUrl == null) { @@ -307,7 +306,7 @@ class _VideoDetailPageVState extends State debugPrint('handlePlay: videoUrl/audioUrl not initialized'); } videoDetailController.queryVideoUrl(); - return; + return null; } } plPlayerController = videoDetailController.plPlayerController; @@ -316,12 +315,13 @@ class _VideoDetailPageVState extends State ..addStatusLister(playerListener) ..addPositionListener(positionListener); if (videoDetailController.plPlayerController.preInitPlayer) { - await plPlayerController!.play(); + return plPlayerController!.play(); } else { - await videoDetailController.playerInit(autoplay: true); + return videoDetailController.playerInit( + autoplay: true, + autoFullScreenFlag: true, + ); } - if (!mounted || !isShowing) return; - await plPlayerController!.autoEnterFullscreen(); } @override diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index c93071cb2..6f35f74ee 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -139,19 +139,6 @@ class PlPlayerController with BlockConfigMixin { /// 视频比例 final Rx videoFit = Rx(VideoFitType.contain); - StreamSubscription? _dataListenerForVideoFit; - StreamSubscription? _dataListenerForEnterFullScreen; - - void _stopListenerForVideoFit() { - _dataListenerForVideoFit?.cancel(); - _dataListenerForVideoFit = null; - } - - void _stopListenerForEnterFullScreen() { - _dataListenerForEnterFullScreen?.cancel(); - _dataListenerForEnterFullScreen = null; - } - /// 后台播放 late final RxBool continuePlayInBackground = Pref.continuePlayInBackground.obs; @@ -384,6 +371,7 @@ class PlPlayerController with BlockConfigMixin { late final showFsLockBtn = Pref.showFsLockBtn; late final keyboardControl = Pref.keyboardControl; + late final bool _autoEnterFullScreen = Pref.autoEnterFullScreen; late final bool autoExitFullscreen = Pref.autoExitFullscreen; late final bool autoPlayEnable = Pref.autoPlayEnable; late final bool enableVerticalExpand = Pref.enableVerticalExpand; @@ -589,6 +577,7 @@ class PlPlayerController with BlockConfigMixin { VideoType? videoType, VoidCallback? onInit, Volume? volume, + bool autoFullScreenFlag = false, }) async { try { _processing = true; @@ -643,6 +632,10 @@ class PlPlayerController with BlockConfigMixin { // 数据加载完成 dataStatus.value = DataStatus.loaded; + if (autoFullScreenFlag && _autoEnterFullScreen) { + triggerFullScreen(status: true); + } + await _initializePlayer(); onInit?.call(); } catch (err, stackTrace) { @@ -882,7 +875,7 @@ class PlPlayerController with BlockConfigMixin { await setPlaybackSpeed(_playbackSpeed.value); } } - getVideoFit(); + _initVideoFit(); // if (_looping) { // await setLooping(_looping); // } @@ -899,26 +892,6 @@ class PlPlayerController with BlockConfigMixin { } } - late final bool enableAutoEnter = Pref.enableAutoEnter; - Future? autoEnterFullscreen() { - if (enableAutoEnter) { - return Future.delayed(const Duration(milliseconds: 500), () { - if (!dataStatus.loaded) { - _stopListenerForEnterFullScreen(); - _dataListenerForEnterFullScreen = dataStatus.listen((status) { - if (status == DataStatus.loaded) { - _stopListenerForEnterFullScreen(); - triggerFullScreen(status: true); - } - }); - } else { - return triggerFullScreen(status: true); - } - }); - } - return null; - } - List? _subscriptions; final Set> _positionListeners = {}; final Set> _statusListeners = {}; @@ -1275,34 +1248,18 @@ class PlPlayerController with BlockConfigMixin { /// Toggle Change the videofit accordingly void toggleVideoFit(VideoFitType value) { - videoFit.value = value; + _prefFit = videoFit.value = value; video.put(VideoBoxKey.cacheVideoFit, value.index); } /// 读取fit - int fitValue = Pref.cacheVideoFit; - void getVideoFit() { - var attr = VideoFitType.values[fitValue]; - // 由于none与scaleDown涉及视频原始尺寸,需要等待视频加载后再设置,否则尺寸会变为0,出现错误; - if (attr == VideoFitType.none || attr == VideoFitType.scaleDown) { - if (buffered.value == Duration.zero) { - attr = VideoFitType.contain; - _stopListenerForVideoFit(); - _dataListenerForVideoFit = dataStatus.listen((status) { - if (status == DataStatus.loaded) { - _stopListenerForVideoFit(); - final attr = VideoFitType.values[fitValue]; - if (attr == VideoFitType.none || attr == VideoFitType.scaleDown) { - videoFit.value = attr; - } - } - }); - } - // fill不应该在竖屏视频生效 - } else if (attr == VideoFitType.fill && isVertical) { - attr = VideoFitType.contain; + var _prefFit = VideoFitType.values[Pref.cacheVideoFit]; + void _initVideoFit() { + if (_prefFit == .fill && _isVertical) { + videoFit.value = .contain; + } else { + videoFit.value = _prefFit; } - videoFit.value = attr; } /// 设置后台播放 @@ -1604,8 +1561,6 @@ class PlPlayerController with BlockConfigMixin { _playerCount = 0; danmakuController = null; - _stopListenerForVideoFit(); - _stopListenerForEnterFullScreen(); _disableAutoEnterPip(); setPlayCallBack(null); dmState.clear(); diff --git a/lib/plugin/pl_player/view/view.dart b/lib/plugin/pl_player/view/view.dart index cfda1e4b5..f9ea8feef 100644 --- a/lib/plugin/pl_player/view/view.dart +++ b/lib/plugin/pl_player/view/view.dart @@ -160,7 +160,7 @@ class _PLVideoPlayerState extends State int? tmpSubtitlePaddingB; StreamSubscription? _controlsListener; - void _controlListener(bool val) { + void _onControlChanged(bool val) { final visible = val && !plPlayerController.controlsLock.value; if ((widget.headerControl.key as GlobalKey).currentState @@ -212,9 +212,11 @@ class _PLVideoPlayerState extends State WidgetsBinding.instance.addObserver(this); _controlsListener = plPlayerController.showControls.listen( - _controlListener, + _onControlChanged, ); + transformationController = TransformationController(); + animationController = AnimationController( vsync: this, duration: const Duration(milliseconds: 100), diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index b881dc547..2ba3ebcaa 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -805,7 +805,7 @@ abstract final class Pref { static bool get enableOnlineTotal => _setting.get(SettingBoxKey.enableOnlineTotal, defaultValue: false); - static bool get enableAutoEnter => + static bool get autoEnterFullScreen => _setting.get(SettingBoxKey.enableAutoEnter, defaultValue: false); static bool get enableAutoLongPressSpeed =>