I am using flutter video player version ^2.4.8 and using seekTo method to skip few sections of video. If I am using video below 720p the seekTo method is working properly and video is getting skipped. But the seekTo method is not working for videos over 720p.
class _VideoTrimmerState extends State<VideoTrimmer> {
late VideoPlayerController _videoPlayerController;
File? _selectedFile;
@override
void initState() {
super.initState();
_initVideoPlayerController();
}
void _initVideoPlayerController() async {
if (_selectedFile != null) {
_videoPlayerController = VideoPlayerController.file(_selectedFile!);
}
_videoPlayerController.addListener(() {
setState(() {});
});
_videoPlayerController.setLooping(true);
_videoPlayerController.initialize();
setState(() {});
}
Future<void> _pickVideo() async {
final picker = ImagePicker();
final pickedFile = await picker.pickVideo(source: ImageSource.gallery);
if (pickedFile != null) {
setState(() {
_selectedFile = File(pickedFile.path);
});
_initVideoPlayerController();
}
}
void _seekTo(Duration duration) {
_videoPlayerController.seekTo(duration);
}
@override
void dispose() {
_videoPlayerController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
//goToNewPosition();
return Scaffold(
body: Column(
children: <Widget>[
Center(
child: _videoPlayerController.value.isInitialized
? AspectRatio(
aspectRatio: _videoPlayerController.value.aspectRatio,
child: VideoPlayer(_videoPlayerController),
)
: Container(),
),
Slider(
value: _videoPlayerController.value.position.inSeconds.toDouble(),
min: 0,
max: _videoPlayerController.value.duration.inSeconds.toDouble(),
onChanged: (double value) {
print("value::$value");
log(value);
/*setState(() {
_videoPlayerController.seekTo(Duration(seconds: value.toInt()));
});*/
},
),
Text(_videoPlayerController.value.position.inSeconds.toString()),
ElevatedButton(
onPressed: () {
_videoPlayerController.value.isPlaying
? _videoPlayerController.pause()
: _videoPlayerController.play();
},
child: Icon(
_videoPlayerController.value.isPlaying
? Icons.pause
: Icons.play_arrow,
)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => _seekTo(Duration(seconds: 10)),
child: Text('10 sec'),
),
SizedBox(width: 10),
ElevatedButton(
onPressed: () => _seekTo(Duration(seconds: 30)),
child: Text('30 sec'),
),
SizedBox(width: 10),
ElevatedButton(
onPressed: () => _seekTo(Duration(seconds: 60)),
child: Text('60 sec'),
),
SizedBox(width: 10),
ElevatedButton(
onPressed: _pickVideo,
child: Text('Select Video'),
),
],
),
],
),
);
}
}
how can use the seekTo method for videos over 720p and above