问题描述
我正在 VideoViewer 中从 url 播放视频。情况是,当我打开播放视频 VideoViewer 在播放视频之前在缓冲时显示一个加载器,如果我在 VideoViewer 加载视频时按下后退按钮,它会在后台播放视频,即使我已经更改了分页。我已经调用了 dispose 并尝试了许多其他方法但它仍然在后台播放整个视频,如果我在加载视频时按后退按钮并且 VideoViewer 正在播放它应用程序工作正常并且视频不在后台播放。
我的代码:
@override
void dispose() {
Wakelock.disable();
videoViewerController.controller.pause();
videoViewerController.dispose();
/*
if(videoViewerController != null) {
videoViewerController.controller.pause();
videoViewerController.dispose();
}*/
super.dispose();
}
Another situtation is if I use **WillPopScope** in this scenario while VideoViewer is loading video it doesn't allow user to go back until loader is gone and video starts playing
代码:
WillPopScope(
onWillPop: () async {
videoViewerController.controller.pause();
videoViewerController.dispose();
Navigator.of(context).pop();
return true;
},
我的整个小部件:
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
videoViewerController.controller.pause();
videoViewerController.dispose();
Navigator.of(context).pop();
return true;
},child: SafeArea(
child: Stack(
children: [
Container(
height: MediaQuery.of(context).size.height,color: Colors.black,child: Center(
child: VideoViewer(
controller: videoViewerController,source: {
"": VideoSource(
video: VideoPlayerController.network(widget.url),)
},autoplay: true,rewindamount: 5,forwardamount: 5,style: VideoViewerStyle(
progressBarStyle: ProgressBarStyle(
barBackgroundColor: Colors.black,barBufferedColor: Colors.grey[500],baractiveColor: Colors.red,),playAndPauseStyle: PlayAndPauseWidgetStyle(
background: Colors.transparent,play: Icon(Icons.play_arrow,color: Colors.white,size: 30),pause: Icon(Icons.pause,header: Container(
child: Align(
alignment: Alignment.topLeft,child: Padding(
padding: const EdgeInsets.only(top: 20,left: 20),child: GestureDetector(
child: Icon(
Icons.arrow_back_ios,color: lightColor,onTap: () {
Navigator.pop(context);
},loading: Center(
child: Container(
width: 70,height: 70,child: CircularProgressIndicator(
valueColor: AlwaysstoppedAnimation<Color>(lightColor),strokeWidth: 3,],);
我也尝试了许多其他方法,但它不起作用。我的所有要求是在返回点击时设置控制器,无论视频是否加载,并停止播放器在后台播放视频,也请不要建议更换播放器,因为我必须使用这个,这是一个要求。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)