0

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()
dda
  • 6,030
  • 2
  • 25
  • 34
Mike
  • 400
  • 2
  • 12
  • well, it does not reset it on my system, python 2.7.2, but i had to remove the `gi.require_version` to make it run. – Rudolf Mühlbauer Oct 13 '12 at 15:32
  • 1
    ah thx for that hint rudolf, it seems to be a problem with gstreamer 1.0, going back to gstreamer0.10 it works, unfortunately though theres missing features in introspection bindings for 0.10 so i guess ill have to work around it for now. – Mike Oct 13 '12 at 15:41

2 Answers2

2

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")
Mike
  • 400
  • 2
  • 12
1

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!

Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60