Skip to content

Commit

Permalink
Fix: fix loss controller after pipstop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackiu1997 committed Jan 29, 2023
1 parent ce9c5e7 commit a259c51
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions lib/pages/live_play/widgets/danmaku_video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,16 @@ class DanmakuVideoPlayerState extends State<DanmakuVideoPlayer> {
void resumePlayer() {
controller = BetterPlayerController(
BetterPlayerConfiguration(
autoPlay: true,
fit: BoxFit.contain,
fullScreenByDefault: widget.fullScreenByDefault,
allowedScreenSleep: widget.allowedScreenSleep,
autoDetectFullscreenDeviceOrientation: true,
autoDetectFullscreenAspectRatio: true,
errorBuilder: errorBuilder,
routePageBuilder: routePageBuilder,
eventListener: ((p0) {
if (p0.betterPlayerEventType == BetterPlayerEventType.pipStart) {
setState(() => _isPipMode = true);
} else if (p0.betterPlayerEventType ==
BetterPlayerEventType.pipStop) {
setState(() => _isPipMode = false);
}
})),
autoPlay: true,
fit: BoxFit.contain,
fullScreenByDefault: widget.fullScreenByDefault,
allowedScreenSleep: widget.allowedScreenSleep,
autoDetectFullscreenDeviceOrientation: true,
autoDetectFullscreenAspectRatio: true,
errorBuilder: errorBuilder,
routePageBuilder: routePageBuilder,
eventListener: pipModeListener,
),
betterPlayerDataSource: BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
widget.url,
Expand All @@ -85,6 +79,14 @@ class DanmakuVideoPlayerState extends State<DanmakuVideoPlayer> {
setState(() {});
}

void pipModeListener(BetterPlayerEvent event) {
if (event.betterPlayerEventType == BetterPlayerEventType.pipStart) {
_isPipMode = true;
} else if (event.betterPlayerEventType == BetterPlayerEventType.pipStop) {
_isPipMode = false;
}
}

void setResolution(String url) {
controller?.setupDataSource(BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
Expand All @@ -110,21 +112,31 @@ class DanmakuVideoPlayerState extends State<DanmakuVideoPlayer> {
return AnimatedBuilder(
animation: animation,
builder: (context, child) {
if (_isPipMode) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: Container(
alignment: Alignment.center,
color: Colors.black,
child: controllerProvider,
),
);
}

return Scaffold(
resizeToAvoidBottomInset: false,
body: Container(
alignment: Alignment.center,
color: Colors.black,
child: Stack(children: [
controllerProvider,
if (!_isPipMode)
DanmakuVideoController(
key: _danmakuFullScreen,
playerKey: _betterPlayerKey,
controller: controller!,
danmakuStream: widget.danmakuStream,
title: widget.room.title,
),
DanmakuVideoController(
key: _danmakuFullScreen,
playerKey: _betterPlayerKey,
controller: controller!,
danmakuStream: widget.danmakuStream,
title: widget.room.title,
),
]),
),
);
Expand Down Expand Up @@ -152,16 +164,6 @@ class DanmakuVideoPlayerState extends State<DanmakuVideoPlayer> {

@override
Widget build(BuildContext context) {
if (controller == null) {
return Center(
child: IconButton(
onPressed: resumePlayer,
icon: const Icon(Icons.refresh_rounded),
iconSize: 30,
),
);
}

return Stack(
children: [
BetterPlayer(
Expand Down

3 comments on commit a259c51

@meetherainday
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

部分虎牙直播间无弹幕

@Jackiu1997
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

部分虎牙直播间无弹幕

这个是已知问题,除非接入虎牙开发者平台,否则某些直播间就是弹幕会获取不到

@meetherainday
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的👌🏻 没想到回复这么快 软件还是很好用的

Please sign in to comment.