我有一个基于 gstreamer 和 dbus http://sourceforge.net/p/autoradiobc/code/210/tree/trunk/autoradio/autoplayer/player_gstreamer1.py的 python 音频播放器。它适用于 pygst,我想将它移植到 gstreamer 1。按照这个如何https://wiki.ubuntu.com/Novacut/GStreamer1.0它可以工作,但是:
File "/home/pat1/svn/autoradio/autoradio/autoplayer/player.py", line 826, in position
except(Gst.QueryError):
File "/usr/lib64/python2.7/site-packages/gi/module.py", line 316, in __getattr__
return getattr(self._introspection_module, name)
File "/usr/lib64/python2.7/site-packages/gi/module.py", line 135, in __getattr__
self.__name__, name))
AttributeError: 'gi.repository.Gst' object has no attribute 'QueryError'
它在这部分代码中:
try:
pos_int = self.player.query_position(Gst.Format.TIME, None)[0]
except(Gst.QueryError):
logging.warning( "Gst.QueryError in query_position" )
return None
在我得到后绕过这个问题:
if ret == Gst.State.CHANGE_FAILURE:
AttributeError: type object 'GstState' has no attribute 'CHANGE_FAILURE'
在这部分代码中:
ret = self.player.set_state(Gst.State.READY)
if ret == Gst.State.CHANGE_FAILURE:
logging.error( "Unable to set the pipeline to the READY state.")
绕过这个问题,我得到:
File "/home/pat1/svn/autoradio/autoradio/autoplayer/player.py", line 659, in on_message_state_changed
(Gst.element_state_get_name(old_state),
File "/usr/lib64/python2.7/site-packages/gi/module.py", line 316, in __getattr__
return getattr(self._introspection_module, name)
File "/usr/lib64/python2.7/site-packages/gi/module.py", line 135, in __getattr__
self.__name__, name))
AttributeError: 'gi.repository.Gst' object has no attribute 'element_state_get_name'
在这部分代码中:
logging.debug("Pipeline state changed from %s to %s. Pendig: %s"%
(Gst.element_state_get_name(old_state),
Gst.element_state_get_name (new_state),
Gst.element_state_get_name (pending_state)))
注释掉 element_state_get_name 播放器将工作....
如何在不绕过损坏代码的情况下将完整代码迁移到 gstreamer 1?