Transferring code from pygst to pyGi

1.5k Views Asked by At

I wanted to build a program which streams radio from address. I wrote the following code:

try: from gi.repository import Gst except AttributeError as e: pass

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)

It worked well when I did

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

but since It gave me several AttributeError and warning claims the module is deprecating I switched to pyGi and imported

from pi.repository import Gst

but then I got the error

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'

I wonder which command in pi.Gst is equivalent to the commands of the pygst? Does anybody know how to transfer this piece of code to PyGi?

1

There are 1 best solutions below

3
On BEST ANSWER

I recommend you install an interpreter with tab completion such as ipython to look up methods. You will find documentation for introspected libs in python at http://lazka.github.io/pgi-docs/

Regarding your specific problem, the call to make is Gst.ElementFactory.make ()

Cheers!