How to jump to frame with flutter video player? - flutter

Is it possible to jump to certain timestamp and display the frame without starting the video using flutter video_player?
I was able to change a frame only when I call play immediately after seekTo.
_videoPlayerController.seekTo(Duration(milliseconds: value));
_videoPlayerController.play();
I also tried
_videoPlayerController.seekTo(Duration(milliseconds: value));
_videoPlayerController.play();
_videoPlayerController.pause();
but it does not change displayed frame of video.

This answer probably comes a bit late, and is totally a hack
It shouldn't really be used, but it allowed me to have a similar behaviour
From what I could find, VideoPlayerController doesn't have any way to interact with the video regarding frames, only timestamps with the seekTo method you used. You just need to play and pause with a little delay in between actions and have it wrapped in an async function so that you can wait for the actions to complete, essentially this:
void moveOneFrameForward() async {
//Gets the current time point at where the video is at in a "Duration" type object
var currentTime = await _videoPlayerController.position;
//Seeks to the current time + an interval, in this case 100ms
await _videoPlayerController.seekTo(
Duration(milliseconds: currentTime!.inMilliseconds + 100),
);
//Plays the video so to render a frame
await _videoPlayerController.play();
//Delay so that the frame is rendered
await Future.delayed(Duration(milliseconds: 10));
//Video is paused to display the frame
await _videoPlayerController.pause();
}

Related

How to match scroll controller `animateTo()` scroll duration with the video playing duration

I am creating a small video editing app it uses Flutter for UI development. But now I had a problem developing the video timeline. I created the timeline by extracting thumbnail for each 1 second of the video and wrapping them in a Row and I wrapped the Row again with a SingleChildScrollView. Then I used ScrollController to automatic scroll when the video playing as follows.
void _scrollThumbnails() {
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
if (_scrollController.hasClients) {
_scrollController.animateTo(
_scrollController.position.maxScrollExtent,
curve: Curves.linear,
duration: Duration(seconds: widget.videoEntity.videoDuration.inSeconds),
);
}
});
}
But it doesn't match perfectly with the video because sometimes video ends before the scroll ends. So how to solve this issue.

How to get the duration of the audio recorded using flutter_sound package?

I am using flutter_sound package for Audio recording. I want to ge the duration of the recorded audio, to send it through an API and also display it in the UI. So, how to approach this?
I was using audioplayers package in my project. So I managed to get the total duration of the audio using the package.
Future<int> _getAudioduration(String audioPath) async {
final AudioPlayer audioPlayer = AudioPlayer();
await audioPlayer.setUrl(audioPath, isLocal: true);
return Future.delayed(
const Duration(seconds: 2),
() => audioPlayer.getDuration(),
);
}
**There may be another solutions for getting the total duration of an audio. This may not be the proper solution. I am posting this here so that someone might find this helpful

do Something with specifed time & firebase

I just want to print "After Time" when my local time is greater than my Firebase data document, but it does nothing when my local time is greater only when I restart my application, it shows up print I want it right now displayed
ssaveTimeToFireStrone() async{
await FirebaseFirestore.instance.collection("TimeToChange").doc("Time").set({
"currentTime":atSixInEvening
});
}
Future getTheTime() async{
final DocumentSnapshot doc=await FirebaseFirestore.instance.collection("TimeToChange").doc("Time").get();
DateTime timeToTriggerEvent=doc["currentTime"].toDate();
// await Future.delayed(Duration(seconds: 5));
// print(timeToTriggerEvent);
if(await DateTime.now().isAfter(timeToTriggerEvent)){
print("after time");
return true;
}
}
Thats because the Future is only called once (probably when you start the app).
If you want to continously check if the time is after the trigger time then you have to put it in a loop. I would suggest a timer that checks once every second (so it doesn't cause any performance impact).
How to use the Timer: How to set an Interval in Flutter?

How to start/stop inactivity timer in Flutter

Is there a way to start an inactivity timer for 5 seconds or X seconds WHILST a function executes?
Here is what I'm doing:
I'm creating a screenshot:
//todo: I need an activity timer [start] here
screenshotController.capture(
//delay: Duration(seconds: 5),
pixelRatio: 2,
path: newPath
).then((io.File image) {
//Capture Done
_imageFile = image;
}).catchError((onError) {
print(onError);
});
// todo: I need an activity timer [stop] here.
The user cannot interrupt the creation of the PNG file. I need some kind of progress timer to start/stop. I do not wish to use Progress_HUD. This is very ugly. I've tried it. I have to change my entire code to accommodate how this app works.
I'm inclined to use CircularProgress..().. but how can I make it start? and how can I make it stop??
How can I know when the screenshotController is still active?
I don't know a lot about screenshot plugin but if you just want to run a function every x seconds you can use Timer
In initState()
void initState() {
super.initState();
Timer.periodic(Duration(seconds: 1), (_) {
//Write here your function and logic
});
}
if your function is async put the timer in didChangeDependencies(),
you can stop the timer by writing some logic

Track progress Flutter video player

Hi I'm using the flutter video player plugin, I have something similar like this [{phrase:"something", startAt: 1039}, {phrase:"other somthing", startAt: 26500}] is there a way to change in ui the phrase based on the start time while the video is playing.
I have try to use a timer with a duration of 100 ms but I retrieve no exact time from the Flutter video player plugin.
You probably want to take a look at stateful widgets as they allow you to do exactly this. In short, you can set phrase to be some variable and once the video starts you can call setState and change the variable. Flutter will automatically redraw the widget and the text will be updated.
To determine if the video player is playing you can add a listener to your video controller.
_controller = VideoPlayerController.network(
'http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_20mb.mp4',
)
..addListener(() {
final bool isPlaying = _controller.value.isPlaying;
if (isPlaying != _isPlaying) {
setState(() {
_isPlaying = isPlaying;
});
}
})
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
});