gpt4 book ai didi

video - 如何在 Flutter 中播放视频列表?

转载 作者:IT王子 更新时间:2023-10-29 07:21:20 46 4
gpt4 key购买 nike

我正在使用 flutter video_player播放视频列表的包。

List sourceList;

sourceList = [
{
"size": 69742504,
"name": "lucky-roulette.mp4",
"mimetype": "video/mp4",
},
{
"size": 69742504,
"name": "BigBuckBunny.mp4",
"mimetype": "video/mp4",
}
];

我已经 checkout this issue ,并在其上做了一些自定义代码。

void play() {
log.fine("Now playing: $_nowPlayingUrl");
_adController = VideoPlayerController.network(_nowPlayingUrl);
_adController.initialize().then((_) => setState(() {}));
_adController.play();
_adController.addListener(checkIfVideoFinished);
}

void checkIfVideoFinished() {
if (_adController == null ||
_adController.value == null ||
_adController.value.position == null ||
_adController.value.duration == null) return;
if (_adController.value.position.inSeconds ==
_adController.value.duration.inSeconds) {
_adController.removeListener(checkIfVideoFinished);
_adController.dispose();
// Change _nowPlayingIndex
setState(() {
_nowPlayingIndex = (_nowPlayingIndex + 1) % _totalIndex;
});
play();
}
}

但是使用这个代码片段会发出一个异常另一个异常被抛出:A VideoPlayerController was used after being disposed.

有没有更好的方法在 Flutter 中播放和循环播放视频列表?

最佳答案

最近我测试了视频列表示例。请检查github中的源FlutterVideoListSample .我认为必须处理视频小部件。

在我的例子中,我在初始化之前清除了旧的 VideoPlayerController。而且我不使用 chewie 插件在进入全屏时创建新页面,因此无法处理下一个视频小部件。

依赖关系
video_player: '>=0.10.11+1 <2.0.0'
FlutterVideoListSample 中的一些代码
VideoPlayerController _controller;

void _initializeAndPlay(int index) async {
print("_initializeAndPlay ---------> $index");
final clip = _clips[index];
final controller = VideoPlayerController.asset(clip.videoPath());
final old = _controller;
if (old != null) {
old.removeListener(_onControllerUpdated);
old.pause(); // mute instantly
}
_controller = controller;
setState(() {
debugPrint("---- controller changed");
});

controller
..initialize().then((_) {
debugPrint("---- controller initialized");
old?.dispose();
_playingIndex = index;
controller.addListener(_onControllerUpdated);
controller.play();
setState(() {});
});
}

关于video - 如何在 Flutter 中播放视频列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55466602/

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