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

View File

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

View File

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