Skip to content

Commit

Permalink
fix: 将自动全屏逻辑调整到播放页,避免未开自动播放时无效果
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Mar 2, 2024
1 parent 0d46ebb commit 77e495e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
10 changes: 10 additions & 0 deletions lib/pages/live_room/view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:PiliPalaX/utils/storage.dart';
import 'package:floating/floating.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -34,8 +35,17 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
}
videoSourceInit();
_futureBuilderFuture = _liveRoomController.queryLiveInfo();
autoEnterFullscreen();
}

void autoEnterFullscreen() async {
bool autoEnterFullscreen =
GStrorage.setting.get(SettingBoxKey.enableAutoEnter, defaultValue: false);
if (autoEnterFullscreen) {
await Future.delayed(const Duration(milliseconds: 100));
plPlayerController!.triggerFullScreen(status: true);
}
}
Future<void> videoSourceInit() async {
_futureBuilder = _liveRoomController.queryLiveInfoH5();
plPlayerController = _liveRoomController.plPlayerController;
Expand Down
1 change: 0 additions & 1 deletion lib/pages/video/detail/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ class VideoDetailController extends GetxController
bvid: bvid,
cid: cid.value,
enableHeart: enableHeart,
isFirstTime: isFirstTime,
autoplay: autoplay,
);

Expand Down
13 changes: 12 additions & 1 deletion lib/pages/video/detail/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ class _VideoDetailPageState extends State<VideoDetailPage>
plPlayerController = videoDetailController.plPlayerController;
plPlayerController!.addStatusLister(playerListener);
listenFullScreenStatus();
autoEnterFullscreen();
}
}

void autoEnterFullscreen() async {
bool autoEnterFullscreen =
setting.get(SettingBoxKey.enableAutoEnter, defaultValue: false);
if (autoEnterFullscreen && videoDetailController.isFirstTime) {
await Future.delayed(const Duration(milliseconds: 100));
plPlayerController!.triggerFullScreen(status: true);
}
}

Expand Down Expand Up @@ -158,6 +168,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
plPlayerController = videoDetailController.plPlayerController;
plPlayerController!.addStatusLister(playerListener);
listenFullScreenStatus();
autoEnterFullscreen();
videoDetailController.autoPlay.value = true;
videoDetailController.isShowCover.value = false;
}
Expand Down Expand Up @@ -195,7 +206,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
});
if (!status) {
showStatusBar();
if (setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)) {
if (horizontalScreen) {
autoScreen();
} else {
verticalScreen();
Expand Down
10 changes: 0 additions & 10 deletions lib/plugin/pl_player/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class PlPlayerController {
int _cid = 0;
int _heartDuration = 0;
bool _enableHeart = true;
bool _isFirstTime = true;
final RxList<Map<String, String>> _vttSubtitles = <Map<String, String>>[].obs;
final RxInt _vttSubtitlesIndex = 0.obs;

Expand Down Expand Up @@ -350,8 +349,6 @@ class PlPlayerController {
int cid = 0,
// 历史记录开关
bool enableHeart = true,
// 是否首次加载
bool isFirstTime = true,
}) async {
try {
_autoPlay = autoplay;
Expand All @@ -365,7 +362,6 @@ class PlPlayerController {
_bvid = bvid;
_cid = cid;
_enableHeart = enableHeart;
_isFirstTime = isFirstTime;

if (_videoPlayerController != null &&
_videoPlayerController!.state.playing) {
Expand Down Expand Up @@ -408,12 +404,6 @@ class PlPlayerController {
}
});
}
bool autoEnterFullcreen =
setting.get(SettingBoxKey.enableAutoEnter, defaultValue: false);
if (autoEnterFullcreen && _isFirstTime) {
await Future.delayed(const Duration(milliseconds: 100));
triggerFullScreen(status: true);
}
} catch (err) {
dataStatus.status.value = DataStatus.error;
print('plPlayer err: $err');
Expand Down

0 comments on commit 77e495e

Please sign in to comment.