Phonon - how to loop a video file
Hi,
I just made use of phonon video play capabilities inside my application and it works ok, problem is that i need to have a video file loop until user presses a key or button.
I've read through phonon module documentation and searched the forum and couldn't find any function/info regarding how to loop a video file, only the basic functions of play, pause, stop
Any suggestions? Thanks in advance.
Re: Phonon - how to loop a video file
Isn't there an event that gets fired when playback is finished?
If that's the case you can write an event handler to start playback again.
Edit:
Just checked it for you: void VideoPlayer::finished () [signal]
Re: Phonon - how to loop a video file
One question regarding your video loop solution: I always get a small pause between the end of the clip and the restart. During this phase, the screen is blank.
Do you have any ideas how to get rid of this pause?
My code looks like this:
Code:
media = new Phonon::MediaObject(this);
media
->setCurrentSource
(Phonon
::MediaSource(QString("/home/my_video.mov")));
Phonon::VideoWidget *videoWidget = new Phonon::VideoWidget(myTargetWidget);
Phonon::createPath(media, videoWidget);
connect(media, SIGNAL(aboutToFinish()), this, SLOT(restartVideo()));
media->play();
and the slot is simply implemented as:
Code:
media
->enqueue
(Phonon
::MediaSource(QString("/home/my_video.mov")));
Re: Phonon - how to loop a video file
There is a signal that comes from the MediaObject - prefinishMarkReached that you can program the timing on. e.g. You can set it to fire a few seconds before the end of the movie. Connect your slot to that and the enqueueing and buffering should all be finished by the time the movie ends.
You can also use the setTransitionTime method to modify transition between playbacks. A negative transition time enables crossfade between two videos on platforms that support it.
I suspect your gap is because your video needs to be loaded a little earlier. Use the prefinishMarkReached signal to start loading sooner...
Re: Phonon - how to loop a video file
Thanks for you hint, but unfortunately the pause is still there. Using the preFinishMarkReached-signal and adjusting the value of the "prefinishMark" did not influence the length of the pause in any way (I tried values up to 5000 milliseconds); the pause is constantly about half a second.
Might the reason be the way the video is encoded (it is a quicktime movie) or is there any other possibility? Can the video be added to the resource file in order to reduce the load time or might this even have nothing to do with loading the video data?
I tried to enqueue the video manually serveral times in a row by simply using
Code:
media->enqueue(*MediaSource)
and the effect is the same: always this small pause inbetween!
Any other ideas?
Re: Phonon - how to loop a video file
Alright, I fixed the problem by simple using "seek(0)" as a reaction to the preFinishMarkReached-Signal instead of using the enqueue- command. Still strange that the other solution did not work out.
Re: Phonon - how to loop a video file
Using seek(0) is good and well when you have only 1 video queued up.
What if you have multiple videos queued up and you want to restart the playlist from the beginning without any pause in between?
I can connect a setQueue function to the aboutToFinish signal, but unless I call clear() on the MediaObject, requeueing does nothing.
If I call clear() while a video file is still playing, the video stops.
The only thing I can do is wait until the last video is finished, then call clear() and then setQueue(my playlist)... This means I have to pause and I don't like that.
Added after 26 minutes:
I solved this by creating another widget underneath the videoplayer widget and made it's background black. This way, during the pause, there was no flicker.