Video seeking does not work (video starts playing at 0 secs) on Flutter (iOS, Chrome, Safari, iPhone). The same code works on Chrome on Mac, an iPad, but just not on an iPhone. This app was deployed using Firebase.
Ideally I'd like my videos to only start playing from a certain point in time. I thought seeking during initialisation would be the way to do it, but it doesn't seem to work on Web on my iPhone, which is the primary use-case I have.
This is my example code.
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
void main() => runApp(const VideoApp());
/// Stateful widget to fetch and then display video content.
class VideoApp extends StatefulWidget {
const VideoApp({super.key});
@override
_VideoAppState createState() => _VideoAppState();
}
class _VideoAppState extends State<VideoApp> {
late VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerControllerworkUrl(Uri.parse(
'.mp4'))
..initialize().then((_) {
_controller.seekTo(Duration(seconds: 3));
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: Center(
child: _controller.value.isInitialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
// _controller.seekTo(Duration(seconds: 3));
_controller.value.isPlaying
? _controller.pause()
: _controller.play();
});
},
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
),
),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}