mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-08-05 18:20:10 +08:00
opt auto fullscreen
opt video fit Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -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<void>? playerInit({bool autoplay = true}) {
|
||||
Future<void>? 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<void> queryLiveUrl() async {
|
||||
Future<void> 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());
|
||||
|
||||
@@ -75,11 +75,9 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
LiveRoomController(heroTag),
|
||||
tag: heroTag,
|
||||
);
|
||||
plPlayerController = _liveRoomController.plPlayerController;
|
||||
PlPlayerController.setPlayCallBack(plPlayerController.play);
|
||||
plPlayerController
|
||||
..autoEnterFullscreen()
|
||||
plPlayerController = _liveRoomController.plPlayerController
|
||||
..addStatusLister(playerListener);
|
||||
PlPlayerController.setPlayCallBack(plPlayerController.play);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -657,13 +657,13 @@ class VideoDetailController extends GetxController
|
||||
playerInit();
|
||||
}
|
||||
|
||||
Future<void>? _initPlayerIfNeeded() {
|
||||
Future<void>? _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<void> 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();
|
||||
|
||||
@@ -162,14 +162,13 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
|
||||
}
|
||||
|
||||
// 获取视频资源,初始化播放器
|
||||
Future<void> 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<VideoDetailPageV>
|
||||
}
|
||||
|
||||
/// 未开启自动播放时触发播放
|
||||
Future<void> handlePlay() async {
|
||||
Future<void>? 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<VideoDetailPageV>
|
||||
debugPrint('handlePlay: videoUrl/audioUrl not initialized');
|
||||
}
|
||||
videoDetailController.queryVideoUrl();
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
plPlayerController = videoDetailController.plPlayerController;
|
||||
@@ -316,12 +315,13 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
|
||||
..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
|
||||
|
||||
@@ -139,19 +139,6 @@ class PlPlayerController with BlockConfigMixin {
|
||||
/// 视频比例
|
||||
final Rx<VideoFitType> videoFit = Rx(VideoFitType.contain);
|
||||
|
||||
StreamSubscription<DataStatus>? _dataListenerForVideoFit;
|
||||
StreamSubscription<DataStatus>? _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<void>? 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<StreamSubscription>? _subscriptions;
|
||||
final Set<ValueChanged<Duration>> _positionListeners = {};
|
||||
final Set<ValueChanged<PlayerStatus>> _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();
|
||||
|
||||
@@ -160,7 +160,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
|
||||
int? tmpSubtitlePaddingB;
|
||||
StreamSubscription? _controlsListener;
|
||||
void _controlListener(bool val) {
|
||||
void _onControlChanged(bool val) {
|
||||
final visible = val && !plPlayerController.controlsLock.value;
|
||||
|
||||
if ((widget.headerControl.key as GlobalKey<TimeBatteryMixin>).currentState
|
||||
@@ -212,9 +212,11 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
|
||||
_controlsListener = plPlayerController.showControls.listen(
|
||||
_controlListener,
|
||||
_onControlChanged,
|
||||
);
|
||||
|
||||
transformationController = TransformationController();
|
||||
|
||||
animationController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 100),
|
||||
|
||||
@@ -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 =>
|
||||
|
||||
Reference in New Issue
Block a user