6 import util.misc as misc_utils
9 _moduleLogger = logging.getLogger(__name__)
12 class SimplePlayer(gobject.GObject):
20 gobject.SIGNAL_RUN_LAST,
22 (gobject.TYPE_STRING, ),
25 gobject.SIGNAL_RUN_LAST,
27 (gobject.TYPE_STRING, ),
30 gobject.SIGNAL_RUN_LAST,
32 (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT),
36 _SERVICE_NAME = "com.nokia.osso_media_server"
37 _OBJECT_PATH = "/com/nokia/osso_media_server"
38 _AUDIO_INTERFACE_NAME = "com.nokia.osso_media_server.music"
41 gobject.GObject.__init__(self)
43 self._state = self.STATE_STOP
49 self.on_playing_done = on_playing_done
51 session_bus = dbus.SessionBus()
53 # Get the osso-media-player proxy object
54 oms_object = session_bus.get_object(
58 follow_name_owner_changes=True,
60 # Use the audio interface
61 oms_audio_interface = dbus.Interface(
63 self._AUDIO_INTERFACE_NAME,
65 self._audioProxy = oms_audio_interface
67 self._audioProxy.connect_to_signal("state_changed", self._on_state_changed)
68 self._audioProxy.connect_to_signal("end_of_stream", self._on_end_of_stream)
80 "audio_codec_not_supported",
82 for error in error_signals:
83 self._audioProxy.connect_to_signal(error, self._on_error)
87 return self.state == self.STATE_PLAY
91 return 0 < len(self._uri)
97 def set_file(self, uri):
99 self._invalidate_cache()
100 if self.state != self.STATE_STOP:
104 self._audioProxy.set_media_location(self._uri)
107 if self.state == self.STATE_PLAY:
108 _moduleLogger.info("Already play")
110 _moduleLogger.info("Play")
111 self._audioProxy.play()
112 self._state = self.STATE_PLAY
113 self.emit("state-change", self.STATE_PLAY)
116 if self.state == self.STATE_PAUSE:
117 _moduleLogger.info("Already pause")
119 _moduleLogger.info("Pause")
120 self._audioProxy.pause()
121 self._state = self.STATE_PAUSE
122 self.emit("state-change", self.STATE_PLAY)
125 if self.state == self.STATE_STOP:
126 _moduleLogger.info("Already stop")
128 self._audioProxy.stop()
129 _moduleLogger.info("Stopped")
130 self._state = self.STATE_STOP
131 self.emit("state-change", self.STATE_STOP)
135 pos_info = self._audioProxy.get_position()
136 if isinstance(pos_info, tuple):
137 self._elapsed, self._duration = pos_info
142 pos_info = self._audioProxy.get_position()
143 if isinstance(pos_info, tuple):
144 self._elapsed, self._duration = pos_info
145 return self._duration
147 def seek_time(self, ns):
148 _moduleLogger.debug("Seeking to: %s", ns)
149 self._audioProxy.seek( dbus.Int32(1), dbus.Int32(ns) )
151 def _invalidate_cache(self):
155 @misc_utils.log_exception(_moduleLogger)
156 def _on_error(self, *args):
157 err, debug = "", repr(args)
158 _moduleLogger.error("Error: %s, (%s)" % (err, debug))
159 self.emit("error", err, debug)
161 @misc_utils.log_exception(_moduleLogger)
162 def _on_end_of_stream(self, *args):
163 self._state = self.STATE_STOP
164 self.emit("eof", self._uri)
166 @misc_utils.log_exception(_moduleLogger)
167 def _on_state_changed(self, state):
168 # @todo Switch to updating/emitting state based on this
169 _moduleLogger.info("State: %s", state)
172 gobject.type_register(GSTStream)