fluttercommunity / chewie

The video player for Flutter with a heart of gold
MIT License
1.94k stars 1.01k forks source link

Fullscreen and landscape only issue #366

Closed Joyker closed 4 years ago

Joyker commented 4 years ago

Helo everybody, i need your help. I have a problem. I want to achieve only fullscreen player in landscape mode.

And leave video player page on back button or leaving fullscreen. Without fullScreenByDefault: true everything seems to be fine. I can just press back button and return to previous screen.

But if it is set to true something goes wrong. Pressing back button or minimize button leads to portrait mode for 1 second and back to landscape, next one to portrait mode. Next finally closes this page. I expect to close the page after first back button or leave fullscreen. And I have no idea what is going wrong. Thanks in advance for any help.

`VideoPlayer({this.title, this.url, this.isLive = false});

final String title; final String url; final bool isLive; @override State createState() { return _VideoPlayerState(); } }

class _VideoPlayerState extends State { VideoPlayerController _videoPlayerController1; ChewieController _chewieController;

@override void initState() { super.initState();

_videoPlayerController1 = VideoPlayerController.network(
    "https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4");
_chewieController = ChewieController(
    videoPlayerController: _videoPlayerController1,
    aspectRatio: _videoPlayerController1.value.aspectRatio,
    autoPlay: true,
    looping: true,
    fullScreenByDefault: true,
    isLive: widget.isLive,
    allowedScreenSleep: false,
    deviceOrientationsAfterFullScreen: [
      DeviceOrientation.landscapeRight,
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]

}

@override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft, ]);

return Scaffold(
  appBar: AppBar(
    title: Text(widget.title),
  ),
  body: SafeArea(
    child: Expanded(
      child: Chewie(
        controller: _chewieController,
      ),
    ),
  ),
);

}

@override void dispose() { _chewieController.dispose(); _videoPlayerController1.dispose();

SystemChrome.setPreferredOrientations([
  DeviceOrientation.landscapeRight,
  DeviceOrientation.landscapeLeft,
  DeviceOrientation.portraitUp,
  DeviceOrientation.portraitDown,
]);

super.dispose();

} }`

Joyker commented 4 years ago

Closed Solution: restrict screen mode to landscape only, dont`t set aspect ratio, set fullScreenByDefault: false, and place chewie inside Expanded ---- Container(height: size.height, width:size.width)

Ahmadre commented 3 years ago

@Joyker after v.0.10.0 you got more control here :) I'll update the readme.