【发布时间】:2019-08-23 07:07:58
【问题描述】:
我正在使用 flutter video_player 包播放视频列表。
List sourceList;
sourceList = [
{
"size": 69742504,
"name": "lucky-roulette.mp4",
"mimetype": "video/mp4",
},
{
"size": 69742504,
"name": "BigBuckBunny.mp4",
"mimetype": "video/mp4",
}
];
我查看了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();
}
}
但是使用这段代码 sn-p 会发出异常Another exception was thrown: A VideoPlayerController was used after being disposed.
有没有更好的方法在 Flutter 中播放和循环播放视频列表?
【问题讨论】:
-
最佳答案应该是,这不是我的,但在 2 个颤振项目中使用并且运行良好 stackoverflow.com/a/58959097/10329023 特别感谢 @igor-kharakhordin 帮助他人和快乐编码:)
标签: video dart flutter video-player