Skip to content

Commit

Permalink
동영상 위에 버튼들 올리기
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanpro committed Apr 2, 2023
1 parent 2dd8f28 commit f8f68b8
Showing 1 changed file with 99 additions and 1 deletion.
100 changes: 99 additions & 1 deletion my_video_player/lib/component/custom_video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,104 @@ class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
if (videoController == null) {
return CircularProgressIndicator();
}
return VideoPlayer(videoController!);
return AspectRatio(
aspectRatio: videoController!.value.aspectRatio,
child: Stack(
children: [
VideoPlayer(videoController!),
_Controls(
onPlayPressed: onPlayPressed,
onReversePressed: onReversePressed,
onForwardPressed: onForwardPressed,
isPlaying: videoController!.value.isPlaying),
Positioned(
right: 0,
child: IconButton(
color: Colors.white,
iconSize: 30.0,
onPressed: () {},
icon: Icon(Icons.photo_camera_back)))
],
));
}

void onPlayPressed() {
setState(() {
if (videoController!.value.isPlaying) {
videoController!.pause();
} else {
videoController!.play();
}
});
}

void onForwardPressed() {
final currentPosition = videoController!.value.position;
final videoDuration = videoController!.value.duration;

Duration position;
if (currentPosition.inSeconds + 3 < videoDuration.inSeconds) {
position = currentPosition + Duration(seconds: 3);
} else {
position = videoDuration;
}
videoController!.seekTo(position);
}

void onReversePressed() {
final currentPosition = videoController!.value.position;
Duration position = Duration();

if (currentPosition.inSeconds > 3) {
position = currentPosition - Duration(seconds: 3);
}
videoController!.seekTo(position);
}
}

class _Controls extends StatelessWidget {
final VoidCallback onPlayPressed;
final VoidCallback onReversePressed;
final VoidCallback onForwardPressed;
final bool isPlaying;

const _Controls(
{required this.onForwardPressed,
required this.onPlayPressed,
required this.onReversePressed,
required this.isPlaying,
Key? key})
: super(key: key);

@override
Widget build(BuildContext context) {
return Container(
color: Colors.black.withOpacity(0.5),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
renderIconButton(
onPressed: onReversePressed, iconData: Icons.rotate_left),
renderIconButton(
onPressed: onPlayPressed,
iconData: isPlaying ? Icons.pause : Icons.play_arrow),
renderIconButton(
onPressed: onForwardPressed, iconData: Icons.rotate_right)
],
),
);
}

Widget renderIconButton({
required VoidCallback onPressed,
required IconData iconData,
}) {
return IconButton(
onPressed: onPressed,
iconSize: 30.0,
color: Colors.white,
icon: Icon(iconData),
);
}
}

0 comments on commit f8f68b8

Please sign in to comment.