opt: 切换页面时销毁播放器组件提升性能

This commit is contained in:
orz12
2024-01-22 12:03:17 +08:00
parent e052c6eafe
commit 569184a507

View File

@ -61,6 +61,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
final Floating floating = Floating();
// 生命周期监听
late final AppLifecycleListener _lifecycleListener;
bool isShowing = true;
@override
void initState() {
@ -216,15 +217,15 @@ class _VideoDetailPageState extends State<VideoDetailPage>
videoIntroController.isPaused = true;
plPlayerController!.removeStatusLister(playerListener);
plPlayerController!.pause();
plPlayerController!.danmakuController?.pause();
plPlayerController!.danmakuController?.clear();
}
setState(() => isShowing = false);
super.didPushNext();
}
@override
// 返回当前页面时
void didPopNext() async {
setState(() => isShowing = true);
videoDetailController.isFirstTime = false;
final bool autoplay = autoPlayEnable;
videoDetailController.playerInit(autoplay: autoplay);
@ -354,6 +355,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
boxConstraints.maxHeight;
return Stack(
children: <Widget>[
if (isShowing)
FutureBuilder(
future: _futureBuilderFuture,
builder: (BuildContext context,
@ -363,7 +365,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
return Obx(
() => !videoDetailController
.autoPlay.value
? const SizedBox()
? nil
: PLVideoPlayer(
controller:
plPlayerController!,