Reputation: 11
I'm trying to play a video and have a button that switches the video to a new one, starting the new one at some point other than the beginning. I haven't written much UI or video-related code.
I have the following that kind of works (very trimmed):
class Main(gobject.GObject):
def __init__(self):
self.player = gst.element_factory_make('playbin', 'VideoPlayer')
#.. pygtk UI/Button code
def next_video(self):
self.player.set_state(gst.STATE_NULL)
self.player.set_property('uri', 'next_video_path')
self.player.set_state(gst.STATE_PAUSED)
end = time.time() + 1
while time.time() < end:
pass
self.player.seek_simple(gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, 100000000000)
self.player.set_state(gst.STATE_PLAYING)
if __name__ == "__main__":
Main(sys.argv)
gtk.main()
A couple points:
Obviously, I'd like a cleaner, more reliable way to do this.
TL;DR: How can I switch from video to video in a pygtk window, starting at an arbitrary point in the video?
Upvotes: 0
Views: 595
Reputation: 5021
Instead of waiting one second, use something like self.player.get_state(timeout=3*gst.SECOND)
to wait for the switch to gst.STATE_PAUSED
to complete.
The timeout is used because if an error occurs and GStreamer doesn't succeed at changing the pipeline state, a get_state
without a timeout will just get stuck waiting forever.
Upvotes: 1