Skip to content

Commit

Permalink
fix: 点进推荐或手动播放产生全屏故障、状态栏跳动;多层推荐性能
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Feb 24, 2024
1 parent 23a4bf1 commit bcf71e5
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 105 deletions.
155 changes: 66 additions & 89 deletions lib/pages/video/detail/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:PiliPalaX/plugin/pl_player/index.dart';
import 'package:PiliPalaX/plugin/pl_player/models/play_repeat.dart';
import 'package:PiliPalaX/services/service_locator.dart';
import 'package:PiliPalaX/utils/storage.dart';
import 'package:status_bar_control/status_bar_control.dart';

import '../../../services/shutdown_timer_service.dart';
import 'widgets/header_control.dart';
Expand Down Expand Up @@ -64,6 +63,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
late final AppLifecycleListener _lifecycleListener;
bool isShowing = true;
RxBool isFullScreen = false.obs;
late StreamSubscription<bool> fullScreenStatusListener;

@override
void initState() {
Expand Down Expand Up @@ -95,7 +95,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
videoSourceInit();
appbarStreamListen();
lifecycleListener();
fullScreenStatusListener();
autoScreen();
}

Expand All @@ -105,6 +104,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
if (videoDetailController.autoPlay.value) {
plPlayerController = videoDetailController.plPlayerController;
plPlayerController!.addStatusLister(playerListener);
listenFullScreenStatus();
}
}

Expand Down Expand Up @@ -140,13 +140,13 @@ class _VideoDetailPageState extends State<VideoDetailPage>
plPlayerController!.play();
}
// 播放完展示控制栏
try {
if (videoDetailController.floating != null) {
PiPStatus currentStatus =
await videoDetailController.floating!.pipStatus;
if (currentStatus == PiPStatus.disabled) {
plPlayerController!.onLockControl(false);
}
} catch (_) {}
}
}
}

Expand All @@ -160,6 +160,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
await videoDetailController.playerInit();
plPlayerController = videoDetailController.plPlayerController;
plPlayerController!.addStatusLister(playerListener);
listenFullScreenStatus();
videoDetailController.autoPlay.value = true;
videoDetailController.isShowCover.value = false;
}
Expand All @@ -185,17 +186,18 @@ class _VideoDetailPageState extends State<VideoDetailPage>
);
}

void fullScreenStatusListener() {
plPlayerController?.isFullScreen.listen((bool isFullScreen) {
if (isFullScreen) {
void listenFullScreenStatus() {
fullScreenStatusListener =
plPlayerController!.isFullScreen.listen((bool status) {
if (status) {
videoDetailController.hiddenReplyReplyPanel();
enterFullScreen();
hideStatusBar();
}
setState(() {
this.isFullScreen.value = isFullScreen;
isFullScreen.value = status;
});
if (!isFullScreen) {
exitFullScreen();
if (!status) {
showStatusBar();
if (setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)) {
autoScreen();
} else {
Expand All @@ -213,6 +215,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
shutdownTimerService.handleWaitingFinished();
if (plPlayerController != null) {
plPlayerController!.removeStatusLister(playerListener);
fullScreenStatusListener.cancel();
plPlayerController!.dispose();
}
if (videoDetailController.floating != null) {
Expand All @@ -221,8 +224,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
videoPlayerServiceHandler.onVideoDetailDispose();
floating.dispose();
_lifecycleListener.dispose();
StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE);
exitFullScreen();
showStatusBar();
super.dispose();
}

Expand All @@ -238,6 +240,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
videoDetailController.defaultST = plPlayerController!.position.value;
videoIntroController.isPaused = true;
plPlayerController!.removeStatusLister(playerListener);
fullScreenStatusListener.cancel();
plPlayerController!.pause();
}
setState(() => isShowing = false);
Expand All @@ -247,10 +250,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
@override
// 返回当前页面时
void didPopNext() async {
if (plPlayerController != null &&
plPlayerController!.videoPlayerController != null) {
setState(() => isShowing = true);
}
videoDetailController.isFirstTime = false;
final bool autoplay = autoPlayEnable;
videoDetailController.playerInit(autoplay: autoplay);
Expand All @@ -265,6 +264,10 @@ class _VideoDetailPageState extends State<VideoDetailPage>
plPlayerController?.play();
}
plPlayerController?.addStatusLister(playerListener);
if (plPlayerController != null) {
listenFullScreenStatus();
}
setState(() => isShowing = true);
super.didPopNext();
}

Expand All @@ -288,8 +291,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>

void autoEnterPip() {
final String routePath = Get.currentRoute;
final bool isPortrait =
MediaQuery.of(context).orientation == Orientation.portrait;

if (autoPiP && routePath.startsWith('/video')) {
floating.enable(
Expand Down Expand Up @@ -340,7 +341,10 @@ class _VideoDetailPageState extends State<VideoDetailPage>
: videoheight,
width: MediaQuery.of(context).size.width,
child: PopScope(
canPop: isFullScreen.value != true,
canPop: isFullScreen.value != true &&
(horizontalScreen ||
MediaQuery.of(context).orientation ==
Orientation.portrait),
onPopInvoked: (bool didPop) {
if (isFullScreen.value == true) {
plPlayerController!
Expand Down Expand Up @@ -519,34 +523,30 @@ class _VideoDetailPageState extends State<VideoDetailPage>
child: TabBarView(
controller: videoDetailController.tabCtr,
children: <Widget>[
Builder(
builder: (BuildContext context) {
return CustomScrollView(
key: const PageStorageKey<String>('简介'),
slivers: <Widget>[
if (videoDetailController.videoType ==
SearchType.video) ...[
const VideoIntroPanel(),
] else if (videoDetailController
.videoType ==
SearchType.media_bangumi) ...[
Obx(() => BangumiIntroPanel(
cid: videoDetailController
.cid.value)),
],
SliverToBoxAdapter(
child: Divider(
indent: 12,
endIndent: 12,
color: Theme.of(context)
.dividerColor
.withOpacity(0.06),
),
),
const RelatedVideoPanel(),
],
);
},
CustomScrollView(
key: const PageStorageKey<String>('简介'),
slivers: <Widget>[
if (videoDetailController.videoType ==
SearchType.video) ...[
const VideoIntroPanel(),
] else if (videoDetailController
.videoType ==
SearchType.media_bangumi) ...[
Obx(() => BangumiIntroPanel(
cid:
videoDetailController.cid.value)),
],
SliverToBoxAdapter(
child: Divider(
indent: 12,
endIndent: 12,
color: Theme.of(context)
.dividerColor
.withOpacity(0.06),
),
),
const RelatedVideoPanel(),
],
),
Obx(
() => VideoReplyPanel(
Expand Down Expand Up @@ -799,54 +799,31 @@ class _VideoDetailPageState extends State<VideoDetailPage>
);
}))
]));
Widget childWhenEnabled = FutureBuilder(
key: Key(heroTag),
future: _futureBuilderFuture,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData && snapshot.data['status']) {
return Obx(
() => !videoDetailController.autoPlay.value
? const SizedBox()
: PLVideoPlayer(
controller: plPlayerController!,
headerControl: HeaderControl(
controller: plPlayerController,
videoDetailCtr: videoDetailController,
),
// danmuWidget: Obx(
// () => PlDanmaku(
// key: Key(
// videoDetailController.danmakuCid.value.toString()),
// cid: videoDetailController.danmakuCid.value,
// playerController: plPlayerController!,
// ),
// ),
),
);
} else {
return nil;
}
},
Widget childWhenEnabled = Obx(
() => !videoDetailController.autoPlay.value
? const SizedBox()
: PLVideoPlayer(
controller: plPlayerController!,
headerControl: HeaderControl(
controller: plPlayerController,
videoDetailCtr: videoDetailController,
),
),
);
// if (!horizontalScreen) {
// if (Platform.isAndroid) {
// return PiPSwitcher(
// childWhenEnabled: childWhenEnabled,
// childWhenDisabled: childWhenDisabled,
// floating: floating,);
// }
// return childWhenDisabled;
// }
return OrientationBuilder(
builder: (BuildContext context, Orientation orientation) {
print("orientation $orientation");
if (!isShowing) {
return const SizedBox();
}
if (orientation == Orientation.landscape) {
enterFullScreen();
if (!horizontalScreen) {
hideStatusBar();
videoDetailController.hiddenReplyReplyPanel();
}
} else if (!isFullScreen.value) {
StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE);
} else {
if (!isFullScreen.value) {
showStatusBar();
}
}
if (Platform.isAndroid) {
return PiPSwitcher(
Expand Down
4 changes: 1 addition & 3 deletions lib/pages/video/detail/widgets/header_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1078,9 +1078,7 @@ class _HeaderControlState extends State<HeaderControl> {
!setting.get(SettingBoxKey.horizontalScreen,
defaultValue: false))
{
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
])
verticalScreen(),
},
Get.back()
}
Expand Down
18 changes: 7 additions & 11 deletions lib/plugin/pl_player/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import 'package:PiliPalaX/services/service_locator.dart';
import 'package:PiliPalaX/utils/feed_back.dart';
import 'package:PiliPalaX/utils/storage.dart';
import 'package:screen_brightness/screen_brightness.dart';
import 'package:status_bar_control/status_bar_control.dart';
import 'package:universal_platform/universal_platform.dart';
// import 'package:wakelock_plus/wakelock_plus.dart';

Expand Down Expand Up @@ -943,12 +942,11 @@ class PlPlayerController {
// 全屏
Future<void> triggerFullScreen({bool status = true}) async {
if (!isFullScreen.value && status) {
await StatusBarControl.setHidden(true, animation: StatusBarAnimation.FADE);
// StatusBarControl.setHidden(true, animation: StatusBarAnimation.FADE);
hideStatusBar();
/// 按照视频宽高比决定全屏方向
toggleFullScreen(true);

/// 进入全屏
await enterFullScreen();
FullScreenMode mode = FullScreenModeCode.fromCode(
setting.get(SettingBoxKey.fullScreenMode, defaultValue: 0))!;
if (mode == FullScreenMode.vertical ||
Expand All @@ -960,15 +958,13 @@ class PlPlayerController {
} else {
await landScape();
}

} else if (isFullScreen.value && !status) {
if (!setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)) {
StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE);
// Get.back();
// await verticalScreen();
}
exitFullScreen();
// StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE);
showStatusBar();
toggleFullScreen(false);
if (!setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)){
await verticalScreen();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/plugin/pl_player/utils/fullscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ Future<void> autoScreen() async {
]);
}

Future<void> enterFullScreen() async {
Future<void> hideStatusBar() async {
await SystemChrome.setEnabledSystemUIMode(
SystemUiMode.immersiveSticky,
);
}

//退出全屏显示
Future<void> exitFullScreen() async {
Future<void> showStatusBar() async {
dynamic document;
late SystemUiMode mode = SystemUiMode.edgeToEdge;
try {
Expand Down

0 comments on commit bcf71e5

Please sign in to comment.