GStreamer属性仅在本地提供

时间:2012-10-13 15:20:25

标签: python gstreamer pygobject

下面的代码是一个测试用例,允许我设置和获取GStreamer URI属性的位置,但它似乎只能在它设置的方法中工作。谁能看到我在这里做错了什么?

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

2 个答案:

答案 0 :(得分:1)

发现gstreamer 1.0具有播放网址和设置网址的单独属性,因此我需要使用

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

而不是

的gstreamer0.10属性
self.player.get_property("uri")

答案 1 :(得分:0)

这一点并不明显,因此在gstreamer-1.0中重复一下,当某些内容正在播放时,self.player.get_property('uri')命令将返回None。

您需要使用self.player.get_property('current-uri')来获取您所追求的值,即使您只是使用self.player.set_property('uri').
If the the file is NOT PLAYING the
设置属性self.player.get_property('current-uri')返回None

总结:
如果文件是播放使用self.player.get_property('current-uri')
如果不使用self.player.get_property('uri')

如果它是一个设计“功能”,它会发臭!