0

下面的代码是一个测试用例,允许我设置和获取 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()
4

2 回答 2

2

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

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

而不是 gstreamer0.10 的属性

self.player.get_property("uri")
于 2012-10-15T13:55:14.330 回答
1

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

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

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

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

于 2015-07-29T06:48:39.490 回答