fluttercommunity / fluttercommunity/chewie
inconsistent behaviour when back button is pressed - videoPlayerController is not disposed after orientation change
- Dominant language
- Dart
- Stars
- 2.1k
- Forks
- 1.1k
- Avg merge
- 6d 8h
- Merged PRs (30d)
- 6
Description
Hi,
New to github issues.
If I start a video, and then hit the back button, the app goes back to the previous screen and the videoPlayerController is disposed as expected.
If I start a video, **change screen orientation,** then hit the back button, the app goes back to the previous screen, but **I can still hear the audio in the background**.
I believe this is a bug?
```
import 'package:flutter/material.dart';
import 'package:swipedetector/swipedetector.dart';
import 'chewie_list_item.dart';
import 'package:video_player/video_player.dart';
class miniLesson extends StatefulWidget{
miniLesson({Key key}) : super(key: key);
@override
State createState() {
return new miniLessonState();
}
}
class miniLessonState extends State {
@override
Widget build(BuildContext context) {
alignment:
Alignment.topCenter;
double deviceWidth = MediaQuery
.of(context)
.size
.width;
double deviceHeight = MediaQuery
.of(context)
.size
.height;
//setBannerQs();
child:
return Scaffold(
body:
new SwipeDetector(
child: Container(
color: Color.fromARGB(10, 10, 10, 10),
alignment: Alignment.topCenter,
child: Container(
//width: deviceWidth-15;
child: ChewieListItem(
videoPlayerController: VideoPlayerController.asset(
'assets/videos/IntroVideo.mp4',
),
looping: false,
),
),
),
),
);
}
}
```
```
chewie_list_item.dart
import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
class ChewieListItem extends StatefulWidget {
// This will contain the URL/asset path which we want to play
final VideoPlayerController videoPlayerController;
final bool looping;
ChewieListItem({
@required this.videoPlayerController,
this.looping,
Key key,
}) : super(key: key);
@override
_ChewieListItemState createState() => _ChewieListItemState();
}
class _ChewieListItemState extends State {
ChewieController _chewieController;
@override
void initState() {
super.initState();
// Wrapper on top of the videoPlayerController
_chewieController = ChewieController(
videoPlayerController: widget.videoPlayerController,
aspectRatio: 9 / 16,
allowFullScreen: false,
//fullScreenByDefault: true,
// Prepare the video to be played and display the first frame
autoInitialize: true,
looping: widget.looping,
// Errors can occur for example when trying to play a video
// from a non-existent URL
errorBuilder: (context, errorMessage) {
return Center(
child: Text(
errorMessage,
style: TextStyle(color: Colors.white),
),
);
},
);
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(0.0),
child: Chewie(
controller: _chewieController,
),
);
}
@override
void dispose() {
super.dispose();
// IMPORTANT to dispose of all the used resources
widget.videoPlayerController.dispose();
_chewieController.dispose();
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.