late VideoPlayerController _phenikaaVideoPlayerController;
late Future<void> _initializeVideoPlayerFuture;
@override
void initState() {
super.initState();
_phenikaaVideoPlayerController = VideoPlayerController.network(
"https://assets-phenikaa-website.s3.ap-southeast-
1.amazonaws.com/media/assets/mo-hinh-3-nha.mp4",
);
// Initialize the controller and store the Future for later use.
_initializeVideoPlayerFuture =
_phenikaaVideoPlayerController.initialize();
}
@override
void dispose() {
_phenikaaVideoPlayerController.dispose();
super.dispose();
}
FutureBuilder(
future: _initializeVideoPlayerFuture,
builder: (_, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Column(
children: [
// If the VideoPlayerController has finished initialization, use
// the data it provides to limit the aspect ratio of the video.
AspectRatio(
aspectRatio:
_phenikaaVideoPlayerController.value.aspectRatio,
// Use the VideoPlayer widget to display the video.
child: VideoPlayer(_phenikaaVideoPlayerController),
),
// show the video progress & scrubbing by touch event on it
VideoProgressIndicator(
_phenikaaVideoPlayerController,
allowScrubbing: true,
padding: EdgeInsets.zero,
colors: VideoProgressColors(
backgroundColor: Color(0xFF243771),
playedColor: R.colors.redFF0000,
bufferedColor: R.colors.grayF5F6F8,
),
),
SizedBox(height: R.dimens.smallSpacing),
Row(
children: [
SizedBox(width: R.dimens.smallSpacing2),
InkWell(
onTap: () {
if (_phenikaaVideoPlayerController.value.isPlaying) {
_phenikaaVideoPlayerController.pause();
} else {
_phenikaaVideoPlayerController.play();
}
},
child: ValueListenableBuilder<VideoPlayerValue>(
valueListenable: _phenikaaVideoPlayerController,
builder: (_, _videoPlayerValue, __) {
return Icon(
_videoPlayerValue.isPlaying
? Icons.pause_circle_outline_rounded
: Icons.play_circle_outline_rounded,
);
},
),
),
SizedBox(width: R.dimens.smallSpacing2),
InkWell(
onTap: () {
_phenikaaVideoPlayerController
.seekTo(Duration(seconds: 0));
_phenikaaVideoPlayerController.pause();
},
child: Icon(Icons.stop_circle_outlined),
),
SizedBox(width: R.dimens.smallSpacing2),
// render duration video with current position / total video duration
ValueListenableBuilder<VideoPlayerValue>(
valueListenable: _phenikaaVideoPlayerController,
builder: (_, _videoPlayerValue, __) {
return Text(
"00:${_videoPlayerValue.position.inSeconds.toString().padLeft(2, '0')}",
style: R.styles.titleTextStyleW500S16,
);
},
),
Text(
" / 00:${_phenikaaVideoPlayerController.value.duration.inSeconds.toString()}",
style: R.styles.titleTextStyleW500S16,
),
Spacer(),
//render Volume button
InkWell(
onTap: () {
if (_phenikaaVideoPlayerController.value.volume ==
0.0) {
_phenikaaVideoPlayerController.setVolume(1.0);
} else
_phenikaaVideoPlayerController.setVolume(0.0);
},
child: ValueListenableBuilder<VideoPlayerValue>(
valueListenable: _phenikaaVideoPlayerController,
builder: (_, _videoPlayerValue, __) {
return Icon(
_videoPlayerValue.volume == 0.0
? Icons.volume_off_outlined
: Icons.volume_up_outlined,
);
},
),
),
SizedBox(width: R.dimens.smallSpacing2),
],
),
],
);
} else {
// If the VideoPlayerController is still initializing, show a
// loading spinner.
return Container(
alignment: Alignment.center,
padding: EdgeInsets.only(top: R.dimens.mediumSpacing1),
child: CircularProgressIndicator(
color: Color(0xFF243771),
),
);
}
},
),
Follow my widget tree with the image demo below
