【发布时间】:2021-10-19 01:32:48
【问题描述】:
要在警报对话框中播放视频,我使用以下代码。但是视频没有播放。是否可以在警报对话框中播放视频?有没有人解决这个问题的,请分享给我。
Future<void> _initializeVideoPlayerFuture;
VideoPlayerController _controller;
_controller = VideoPlayerController.network(
video_base_url+videoUrl,
);
// Initialize the controller and store the Future for later use.
_initializeVideoPlayerFuture = _controller.initialize();
// Use the controller to loop the video.
_controller.setLooping(true);
// If the video is playing, pause it.
if (_controller.value.isPlaying) {
_controller.pause();
} else {
// If the video is paused, play it.
_controller.play();
}
ContainerResponsive(
alignment: Alignment.center,
width: MediaQuery.of(context).size.width-50,
height: 150,
child: FutureBuilder(
future: _initializeVideoPlayerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
// If the VideoPlayerController has finished initialization, use
// the data it provides to limit the aspect ratio of the video.
return AspectRatio(
aspectRatio: _controller.value.aspectRatio,
// Use the VideoPlayer widget to display the video.
child: VideoPlayer(_controller),
);
} else {
// If the VideoPlayerController is still initializing, show a
// loading spinner.
return const Center(
child: CircularProgressIndicator(),
);
}
},
)
),
【问题讨论】:
-
这能回答你的问题吗? Flutter how do i show a video in alertDialog
-
是的......但我使用它的方式相同。但是我的视频在第一帧就停止了。
-
您是否将自动播放设置为 true?
-
是的,我加了。
-
如果我在 InitState 中初始化播放器,它正在工作。但我的要求是当我单击 gridview 项目警报对话框时将打开。然后我会点击播放按钮。
标签: android flutter video video-player