0

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?

Danis Fischer
  • 375
  • 1
  • 7
  • 27

1 Answers1

2

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!

Mathieu_Du
  • 787
  • 4
  • 10
  • 1
    Thanks but then I get `AttributeError: 'gi.repository.Gst' object has no attribute 'STATE_PLAYING'`. – Danis Fischer Jan 23 '15 at 15:54
  • 1
    Gst.State.PLAYING, but you should really look at the page I linked and install ipython as I suggested ;) – Mathieu_Du Jan 24 '15 at 11:38
  • Mathieu, could you please elaborate on this "interpreter with tab completion"? Like a simple basic use case, this sounds interesting. – yPhil Jun 29 '16 at 02:54