Search code examples
pythongstreamerpygobject

GStreamer properties only available locally


The code below is a test case to allow me to set and get the location of a GStreamer URI property, but it seems to only work within the method that it's set to. Can anyone see what I'm doing wrong here?

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GObject
import time

GObject.threads_init()
Gst.init(None)

class MusicPlayer(object):
    def __init__(self):
        self.player = Gst.ElementFactory.make("playbin", "player")
        fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
        self.player.set_property("video-sink", fakesink)

    def set_track(self, filepath):
        filepath = filepath.replace('%', '%25').replace('#', '%23')
        self.player.set_property("uri", filepath)
        print(self.player.get_property("uri"))#prints the correct information

    def get_track(self):
        return self.player.get_property("uri")

    def play_item(self):
        self.player.set_state(Gst.State.PLAYING)

    def pause_item(self):
        self.player.set_state(Gst.State.PAUSED)

    def stop_play(self):
        self.player.set_state(Gst.State.NULL)

import time
def main():
    app = MusicPlayer()
    app.set_track("file:///media/Media/Music/Bob Dylan/Modern Times/06 - Workingman's Blues #2.ogg")
    app.play_item()
    print(app.get_track())#prints 'None'
    time.sleep(5)
    app.pause_item()
    time.sleep(1)
    app.play_item()
    time.sleep(5)
    app.stop_play()

main()

Solution

  • found out that gstreamer 1.0 has seperate propertys for the playing url and the set url, as such i needed to use

    self.player.get_property("current-uri")
    

    instead of the gstreamer0.10 property of

    self.player.get_property("uri")