2

我有一个基于 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?

4

1 回答 1

2

我找不到关于 QueryError 的第一个问题的解决方案

但 :

if ret == Gst.State.CHANGE_FAILURE:

变得:

if ret == Gst.StateChangeReturn.FAILURE:

和:

Gst.element_state_get_name(old_state)

变得:

Gst.Element.state_get_name(old_state)

和:

      self.player.set_new_stream_time(0L)

变得:

      self.player.set_start_time(0L)

和:

     event = Gst.event_new_seek(1.0, Gst.Format.TIME,
             Gst.SeekFlags.FLUSH|Gst.SeekFlags.ACCURATE,
             Gst.SEEK_TYPE_SET, tnano, Gst.SEEK_TYPE_NONE, 0)

变得:

     event = Gst.Event.new_seek(1.0, Gst.Format.TIME,
             Gst.SeekFlags.FLUSH|Gst.SeekFlags.ACCURATE,
             Gst.SeekType.SET, tnano, Gst.SeekType.NONE, 0)

和:

    pos_int = self.player.query_duration(Gst.Format.TIME, None)[0]

变得:

    pos_int = self.player.query_duration(Gst.Format.TIME)[1]
于 2013-08-20T10:51:49.123 回答