将代码从pygst传输到pyGi

时间:2015-01-23 11:34:17

标签: python python-2.7 gstreamer pygi-aio

我想建立一个从地址传输无线电的程序。我写了以下代码:

尝试:     来自gi.repository import Gst 除了AttributeError为e:     通

def on_tag(bus, msg):
    taglist = msg.parse_tag()
    print 'on_tag:'
    for key in taglist.keys():
        print '\t%s = %s' % (key, taglist[key])

music_stream_uri = 'http://213.8.143.168/91fmAudio'
player = Gst.element_factory_make("playbin", "player")
player.set_property('uri', music_stream_uri)
player.set_state(Gst.STATE_PLAYING)

我做的时候效果很好

import pygst    
pygst.require("0.10")
import gst

但是因为它给了我几个AttributeError和警告声明该模块已弃用我切换到pyGi并导入

from pi.repository import Gst

然后我收到了错误

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.1\helpers\pydev\pydevd.py", line 2222, in <module>
    globals = debugger.run(setup['file'], None, None)
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.1\helpers\pydev\pydevd.py", line 1648, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:/Danis/radio/radio.py", line 20, in <module>
    player = Gst.element_factory_make("playbin", "player")
  File "C:\Python27\lib\site-packages\gi\module.py", line 320, in __getattr__
    return getattr(self._introspection_module, name)
  File "C:\Python27\lib\site-packages\gi\module.py", line 139, in __getattr__
self.__name__, name))
AttributeError: 'gi.repository.Gst' object has no attribute   'element_factory_make'

我想知道pi.Gst中的哪个命令等同于pygst的命令?有人知道如何将这段代码传递给PyGi吗?

1 个答案:

答案 0 :(得分:2)

我建议您安装带有标签完成功能的解释器,例如ipython,以查找方法。您将在http://lazka.github.io/pgi-docs/

的python中找到有关内省库的文档

关于您的具体问题,对make的调用是Gst.ElementFactory.make()

干杯!