gpt4 book ai didi

android - 如何停止在后台 chewie 插件中播放视频

转载 作者:行者123 更新时间:2023-12-03 04:20:34 25 4
gpt4 key购买 nike

我正在使用 chewie 插件播放视频问题是,当我浏览另一个 Activity 或单击主页按钮时,视频在后台连续播放如何在转到另一个 Activity 或单击主页按钮时停止

import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.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<ChewieListItem> {
ChewieController _chewieController;

@override
void initState() {
super.initState();
// Wrapper on top of the videoPlayerController
_chewieController = ChewieController(
videoPlayerController: widget.videoPlayerController,
aspectRatio: 16 / 9,
// Prepare the video to be played and display the first frame
autoInitialize: true,
looping: widget.looping,
deviceOrientationsAfterFullScreen:[DeviceOrientation.portraitUp] ,
// 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(8.0),
child: Chewie(
controller: _chewieController,
),
);
}

@override
void dispose() {
super.dispose();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
// IMPORTANT to dispose of all the used resources
widget.videoPlayerController.dispose();
_chewieController.dispose();
}
}

我的视频播放器

ChewieListItem(
videoPlayerController: VideoPlayerController.network(
'https://streamer12.vdn.dstreamone.net/livinghope/livinghope/playlist.m3u8',),
)

最佳答案

现在我在这里回答我自己的问题是一个简单的解决方案,在小部件 videoplayer dispose 方法下使用了这个 _chewieController.pause();

      @override
void dispose() {
super.dispose();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
// IMPORTANT to dispose of all the used resources
widget.videoPlayerController.dispose();
_chewieController.dispose();
_chewieController.pause();
}

关于android - 如何停止在后台 chewie 插件中播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62857679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com