Mike
Mike

Reputation: 420

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()

Upvotes: 1

Views: 1008

Answers (2)

Rolf of Saxony
Rolf of Saxony

Reputation: 22443

It is not obvious and thus bears repeating that in gstreamer-1.0 when something is playing the self.player.get_property('uri') command will return None.

You need to use self.player.get_property('current-uri') to get the value that you are after, even if you just set the property using self.player.set_property('uri').
If the the file is NOT PLAYING the
self.player.get_property('current-uri') returns None

To summarise:
if the file is PLAYING use self.player.get_property('current-uri')
if not use self.player.get_property('uri')

if it is a design "feature" it stinks!

Upvotes: 1

Mike
Mike

Reputation: 420

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")

Upvotes: 2

Related Questions