如何使用默认的视频播放器实现动态更改Flutter'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4'中的视频?
void initState() {
// Create and store the VideoPlayerController. The VideoPlayerController
// offers several different constructors to play videos from assets, files,
// or the internet.
_controller = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4',
);
// Initialize the controller and store the Future for later use.
_initializeVideoPlayerFuture = _controller.initialize();
// Use the controller to loop the video.
_controller.setLooping(true);
super.initState();
}
您是否尝试过,
void initState() {
// Initialize the controller and store the Future for later use.
_initializeVideoPlayerFuture = _controller.initialize();
setUpVideo('https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4');
super.initState();
}
setUpVideo(String url){
// Create and store the VideoPlayerController. The VideoPlayerController
// offers several different constructors to play videos from assets, files,
// or the internet.
_controller = VideoPlayerController.network(
url,
);
// Use the controller to loop the video.
_controller.setLooping(true);
}
现在在代码调用setState
中的任何位置,
setState(() {
setUpVideo('another_url');
});