youtube_player_flutter
youtube_player_flutter copied to clipboard
Custom Seek bar (seekto() function )is not working in v3.0.4
Describe the bug The player is working fine but seek bar is not working To Reproduce
initiaize
late final YoutubePlayerController controller;
@override
void initState() {
controller = YoutubePlayerController(
params: const YoutubePlayerParams(
showControls: false,
strictRelatedVideos: false,
enableJavaScript: true,
mute: false,
))
..onInit = () {
controller.loadVideoById(
videoId: widget.videoUrl,
startSeconds: 0,
);
controller.playVideo();
};
super.initState();
}
// player
SizedBox(
width: Dimension.flullScreen,
height: Dimension.flullScreen,
child: YoutubePlayer(
controller: controller,
aspectRatio: 16 / 9,
),
),
seek bar
Widget VideoPositionIndicator(YoutubePlayerController controller) {
return YoutubeValueBuilder(
controller: controller,
builder: (context, val) {
return StreamBuilder<Duration>(
stream: controller.getCurrentPositionStream(),
initialData: Duration.zero,
builder: (context, snapshot) {
num position = snapshot.data?.inSeconds ?? 0;
final duration = controller.metadata.duration.inSeconds;
log("$position $duration ${position / duration}");
return SliderTheme(
data: SliderThemeData(inactiveTrackColor: Colors.blue[400]),
child: Slider(
value: (position / duration).toString() == "NaN"
? 0
: position / duration,
onChanged: (value) {
setState(() {
log((value * duration).toString() + " this is value ");
controller.seekTo(seconds: (value * duration).toDouble());
position = value * duration;
});
},
min: 0,
max: 1,
),
);
},
);
});
}
Expected behavior when pressing seek bar we need to change the video possision
Technical Details:
- Device: Android emulator Api31
I am facing kind of a similar issue.
Changing Video position from the video controls works & can be detected by setting up a getCurrentPositionStream().
But using the seekto() function does not work fine, does not play when called from playing state & messes up the position stream.
You can do like this.
https://github.com/sarbagyastha/youtube_player_flutter/blob/667ce9a0d0d42eb491186353fce63a4484d0941f/packages/youtube_player_iframe/example/lib/main.dart#L222-L271
it has the same issue i think the seek function is not working ?