Missing PyGST Plugin?
I'm running python 2.6 and PyGST (most recent available for Python 2.6). I've installed all the plugins - good, bad, and ugly.
I have the following code:
import sys, os
import pygtk, gtk, gobject
import pygst
pygst.require("0.10")
import gst
class GTK_Main:
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Audio-Player")
window.set_default_size(300, -1)
win开发者_如何学运维dow.connect("destroy", gtk.main_quit, "WM destroy")
vbox = gtk.VBox()
window.add(vbox)
self.entry = gtk.Entry()
vbox.pack_start(self.entry, False, True)
self.button = gtk.Button("Start")
self.button.connect("clicked", self.start_stop)
vbox.add(self.button)
window.show_all()
self.player = gst.element_factory_make("playbin2", "player")
fakesink = gst.element_factory_make("fakesink", "fakesink")
self.player.set_property("video_sink", fakesink)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.connect("message", self.on_message)
def start_stop(self, w):
if self.button.get_label() == "Start":
filepath = self.entry.get_text()
if os.path.isfile(filepath):
self.button.set_label("Stop")
self.player.set_property("uri", filepath)
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.MESSAGE_EOS:
self.player.set_state(gst.STATE_NULL)
self.button.set_label("Start")
elif t == gst.MESSAGE_ERROR:
self.player.set_state(gst.STATE_NULL)
err, debug = message.parse_error()
print "Error: %s" % err, debug
self.button.set_label("Start")
GTK_Main()
gtk.gdk.threads_init()
gtk.main()
However, when I run this module and try to open a file, I get the following error.
Error: Your GStreamer installation is missing a plug-in. ..........\Source\gst-plugins-base\gst\playback\gsturidecodebin.c(991): gen_source_element (): /GstPlayBin2:player/GstURIDecodeBin:uridecodebin0
How do I correct this?
EDIT: The first answer works on Ubuntu, but it does not work on Windows. Bounty will be awarded to whoever solves the problem for Windows.
What you need is a full uri: if you handle only files on your local filesystem and want to insert the file path only, change the line
self.player.set_property("uri", filepath)
to something like this:
self.player.set_property("uri", "file://"+filepath)
AND: GST has some routines to handle uri better the just prepending 'file://'
.
A good tutorial is here
Some research has shown that this is apparently an error in a DLL. Tweaks may need to be made to the source, and the source compiled, instead of using WinBuilds.
精彩评论