fix: back press gesture blocked

fix: portrait player state issue
closes #49
This commit is contained in:
2025-06-05 11:26:49 +01:00
parent 0d8ce78009
commit 5ffab5f7bf
3 changed files with 22 additions and 20 deletions

View File

@ -139,17 +139,13 @@ class _LivePage extends State<LivePage>
Widget build(BuildContext context) {
final mq = MediaQuery.of(context);
return PopScope(
canPop: false,
canPop: !_streaming,
onPopInvokedWithResult: (didPop, result) async {
if (_streaming) {
if (_streaming && !didPop) {
final go = await showExitStreamDialog(context);
if (context.mounted) {
if (go == true) {
context.go("/");
}
if (context.mounted && go == true) {
context.go("/");
}
} else {
context.go("/");
}
},
child: ValueListenableBuilder(

View File

@ -57,7 +57,7 @@ class StreamPage extends StatefulWidget {
class _StreamPage extends State<StreamPage> with RouteAware {
bool _offScreen = false;
StreamEvent? _stream;
final GlobalKey _playerKey = GlobalKey();
bool isWidgetVisible(BuildContext context) {
final router = GoRouter.of(context);
@ -132,11 +132,11 @@ class _StreamPage extends State<StreamPage> with RouteAware {
final streamWidget = _buildPlayer(ctx, stream);
return ValueListenableBuilder(
valueListenable: mainPlayer.state,
builder: (context, state, player) {
if (state?.isPortrait == true) {
return _buildPortraitStream(context, stream, player!);
builder: (context, playerState, child) {
if (playerState?.isPortrait == true) {
return _buildPortraitStream(context, stream, child!);
}
return _buildLandscapeStream(context, stream, player!);
return _buildLandscapeStream(context, stream, child!);
},
child: streamWidget,
);
@ -147,6 +147,7 @@ class _StreamPage extends State<StreamPage> with RouteAware {
Widget _buildPlayer(BuildContext context, StreamEvent stream) {
return (stream.info.stream != null && !_offScreen)
? MainVideoPlayerWidget(
key: _playerKey,
url: stream.info.stream!,
placeholder: stream.info.image,
isLive: true,
@ -170,7 +171,6 @@ class _StreamPage extends State<StreamPage> with RouteAware {
return Stack(
children: [
child,
Positioned(child: child),
Positioned(
child: Container(

View File

@ -60,7 +60,7 @@ class MainPlayer extends BaseAudioHandler {
Future<void> dispose() async {
await super.stop();
await _controller?.dispose();
_chewieController!.dispose();
_chewieController?.dispose();
_controller = null;
_chewieController = null;
state.value = null;
@ -126,6 +126,7 @@ class MainPlayer extends BaseAudioHandler {
: null,
);
// insert media item
mediaItem.add(
MediaItem(
@ -139,6 +140,8 @@ class MainPlayer extends BaseAudioHandler {
: null,
),
);
// Update player state immediately after initialization
updatePlayerState();
_url = url;
} catch (e) {
if (e is PlatformException && e.code == "VideoError") {
@ -179,10 +182,13 @@ class MainPlayer extends BaseAudioHandler {
},
),
);
state.value = PlayerState(
width: _controller!.value.size.width.floor(),
height: _controller!.value.size.height.floor(),
isPlaying: isPlaying,
);
if (_controller?.value.isInitialized == true && _controller!.value.size != Size.zero) {
state.value = PlayerState(
width: _controller!.value.size.width.floor(),
height: _controller!.value.size.height.floor(),
isPlaying: isPlaying,
);
}
}
}