[Gambas-user] MediaPlayer bug with AboutToFinish and URL?

Piper984 mclennan at ...3614...
Tue Oct 18 13:18:10 CEST 2016


OK, thanks for continuing to look into it!

In case it helps: Below is a Python script + Gstreamer lib where setting the
URL property behaves as expected.  It just toggles between playing two video
clips, setting the URL property when the 'about-to-finish' event fires. Not
sure if this will be of any use, but it might?  I ran this script w/ Ubuntu
16.04 and GStreamer 1.8.2, which is a different system than the one I
originally asked about.  I have confirmed that running Gambas 3.9.0 on the
same system that the Python script below runs doesn't behave as expected.

Thanks again!

<code>
#!/usr/bin/env python

import sys, os
import gi
gi.require_version('Gst', '1.0')
gi.require_version('Gtk', '3.0')
gi.require_version('GstVideo', '1.0') 
from gi.repository import Gst, GObject, Gtk
 
# Needed for window.get_xid(), xvimagesink.set_window_handle(),
respectively:
from gi.repository import GdkX11, GstVideo

class GTK_Main(object):
      
	def __init__(self):
		window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
		window.set_title("Video-Player")
		window.set_default_size(500, 400)
		window.connect("destroy", Gtk.main_quit, "WM destroy")
		vbox = Gtk.VBox()
		window.add(vbox)
		hbox = Gtk.HBox()
		vbox.pack_start(hbox, False, False, 0)
		self.entry = Gtk.Entry()
		hbox.add(self.entry)
		self.button = Gtk.Button("Start")
		hbox.pack_start(self.button, False, False, 0)
		self.button.connect("clicked", self.start_stop)
		self.movie_window = Gtk.DrawingArea()
		vbox.add(self.movie_window)
		window.show_all()
		self.iPos = 0
		self.player = Gst.ElementFactory.make("playbin", "player")
		bus = self.player.get_bus()
		bus.add_signal_watch()
		bus.enable_sync_message_emission()
		bus.connect("message", self.on_message)
		bus.connect("sync-message::element", self.on_sync_message)
		self.player.connect("about-to-finish",  self.finished)
		
        
	def finished(self, player):
		print "About to Finish"
		if self.iPos == 0:
			self.player.set_property("uri", "file:///home/chris/Desktop/test5.mp4" )
			self.iPos = 1
		else:
			self.player.set_property("uri", "file:///home/chris/Desktop/output.mp4" )
			self.iPos = 0
		        
	def start_stop(self, w):
		if self.button.get_label() == "Start":
			filepath = self.entry.get_text().strip()
			if os.path.isfile(filepath):
				filepath = os.path.realpath(filepath)
				self.button.set_label("Stop")
				self.player.set_property("uri", "file:///home/chris/Desktop/output.mp4"
)
				self.player.set_state(Gst.State.PLAYING)
		else:
			self.player.set_state(Gst.State.NULL)
			self.button.set_label("Start")      
                
	def on_message(self, bus, message):
		t = message.type
		if t == Gst.MessageType.EOS:
			self.player.set_state(Gst.State.NULL)
			self.button.set_label("Start")
		elif t == Gst.MessageType.ERROR:
			self.player.set_state(Gst.State.NULL)
			err, debug = message.parse_error()
			print "Error: %s" % err, debug
			self.button.set_label("Start")
            
	def on_sync_message(self, bus, message):
		if message.get_structure().get_name() == 'prepare-window-handle':
			imagesink = message.src
			imagesink.set_property("force-aspect-ratio", True)
		
imagesink.set_window_handle(self.movie_window.get_property('window').get_xid())
 
		
GObject.threads_init()
Gst.init(None)        
GTK_Main()
Gtk.main()



</code>






--
View this message in context: http://gambas.8142.n7.nabble.com/MediaPlayer-bug-with-AboutToFinish-and-URL-tp57513p57595.html
Sent from the gambas-user mailing list archive at Nabble.com.




More information about the User mailing list