Results 1 to 7 of 7

Thread: Phonon - how to loop a video file

  1. #1
    Join Date
    Feb 2007
    Posts
    39
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  2. #2
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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]
    Last edited by boudie; 28th October 2009 at 21:28.

  3. #3
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4

    Question 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:

    Qt Code:
    1. media = new Phonon::MediaObject(this);
    2. media->setCurrentSource(Phonon::MediaSource(QString("/home/my_video.mov")));
    3.  
    4. Phonon::VideoWidget *videoWidget = new Phonon::VideoWidget(myTargetWidget);
    5. Phonon::createPath(media, videoWidget);
    6.  
    7. connect(media, SIGNAL(aboutToFinish()), this, SLOT(restartVideo()));
    8. media->play();
    To copy to clipboard, switch view to plain text mode 

    and the slot is simply implemented as:

    Qt Code:
    1. media->enqueue(Phonon::MediaSource(QString("/home/my_video.mov")));
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jun 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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...

  5. #5
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4

    Question 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
    Qt Code:
    1. media->enqueue(*MediaSource)
    To copy to clipboard, switch view to plain text mode 
    and the effect is the same: always this small pause inbetween!

    Any other ideas?

  6. #6
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4

    Thumbs up 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.

  7. #7

    Default 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.
    Last edited by doakey3; 24th July 2015 at 19:57.

Similar Threads

  1. open a video file in a new window...
    By jiapei100 in forum Qt Programming
    Replies: 0
    Last Post: 19th September 2009, 15:53
  2. Replies: 3
    Last Post: 5th July 2009, 18:22
  3. grab images from Phonon video
    By Kraut~salat in forum Qt Programming
    Replies: 3
    Last Post: 19th January 2009, 10:53
  4. Video freezes during mpeg video playback using Phonon
    By davejames in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2009, 09:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.