6 import util.misc as misc_utils
9 _moduleLogger = logging.getLogger(__name__)
12 class Stream(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
48 session_bus = dbus.SessionBus()
50 # Get the osso-media-player proxy object
51 oms_object = session_bus.get_object(
55 follow_name_owner_changes=True,
57 # Use the audio interface
58 oms_audio_interface = dbus.Interface(
60 self._AUDIO_INTERFACE_NAME,
62 self._audioProxy = oms_audio_interface
64 self._audioProxy.connect_to_signal("state_changed", self._on_state_changed)
65 self._audioProxy.connect_to_signal("end_of_stream", self._on_end_of_stream)
77 "audio_codec_not_supported",
79 for error in error_signals:
80 self._audioProxy.connect_to_signal(error, self._on_error)
84 return self.state == self.STATE_PLAY
88 return 0 < len(self._uri)
94 def set_file(self, uri):
96 self._invalidate_cache()
97 if self.state != self.STATE_STOP:
101 self._audioProxy.set_media_location(self._uri)
104 if self.state == self.STATE_PLAY:
105 _moduleLogger.info("Already play")
107 _moduleLogger.info("Play")
108 self._audioProxy.play()
109 self._state = self.STATE_PLAY
110 self.emit("state-change", self.STATE_PLAY)
113 if self.state == self.STATE_PAUSE:
114 _moduleLogger.info("Already pause")
116 _moduleLogger.info("Pause")
117 self._audioProxy.pause()
118 self._state = self.STATE_PAUSE
119 self.emit("state-change", self.STATE_PLAY)
122 if self.state == self.STATE_STOP:
123 _moduleLogger.info("Already stop")
125 self._audioProxy.stop()
126 _moduleLogger.info("Stopped")
127 self._state = self.STATE_STOP
128 self.emit("state-change", self.STATE_STOP)
132 pos_info = self._audioProxy.get_position()
133 if isinstance(pos_info, tuple):
134 self._elapsed, self._duration = pos_info
139 pos_info = self._audioProxy.get_position()
140 if isinstance(pos_info, tuple):
141 self._elapsed, self._duration = pos_info
142 return self._duration
144 def seek_time(self, ns):
145 _moduleLogger.debug("Seeking to: %s", ns)
146 self._audioProxy.seek( dbus.Int32(1), dbus.Int32(ns) )
148 def _invalidate_cache(self):
152 @misc_utils.log_exception(_moduleLogger)
153 def _on_error(self, *args):
154 err, debug = "", repr(args)
155 _moduleLogger.error("Error: %s, (%s)" % (err, debug))
156 self.emit("error", err, debug)
158 @misc_utils.log_exception(_moduleLogger)
159 def _on_end_of_stream(self, *args):
160 self._state = self.STATE_STOP
161 self.emit("eof", self._uri)
163 @misc_utils.log_exception(_moduleLogger)
164 def _on_state_changed(self, state):
165 # @todo Switch to updating/emitting state based on this
166 _moduleLogger.info("State: %s", state)
169 gobject.type_register(Stream)