From 8c5a15b92ba7a1728a297bd948d4de0a78b85da4 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Tue, 28 Dec 2010 14:44:59 +0100 Subject: Use gobject.idle_add() for actions to prevent Totem from crashing --- airplay.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/airplay.py b/airplay.py index dd3211d..0ffa75e 100644 --- a/airplay.py +++ b/airplay.py @@ -20,6 +20,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +import gobject import totem import platform import time @@ -56,7 +57,7 @@ class AirPlayTotemPlayer(AirPlayService): # this must seek to a certain time def set_scrub(self, position): if self.totem.is_seekable(): - self.totem.action_seek_time(int(float(position) * 1000)) + gobject.idle_add(self.totem.action_seek_time, int(float(position) * 1000)) # this only sets the location and start position, it does not yet start to play def play(self, location, position): @@ -65,7 +66,7 @@ class AirPlayTotemPlayer(AirPlayService): # stop the playback completely def stop(self, info): - self.totem.action_stop() + gobject.idle_add(self.totem.action_stop) # reverse HTTP to PTTH def reverse(self, info): @@ -75,13 +76,15 @@ class AirPlayTotemPlayer(AirPlayService): def rate(self, speed): if (int(float(speed)) >= 1): if self.location is not None: + timeout = 5 # start playback and loading of media - self.totem.add_to_playlist_and_play(self.location[0], "AirPlay Video", False) + gobject.idle_add(self.totem.add_to_playlist_and_play, self.location[0], "AirPlay Video", False) # wait until stream-length is loaded and is not zero duration = 0 - while (int(duration) == 0): - duration = float(self.totem.get_property('stream-length') / 1000) + while (int(duration) == 0 and timeout > 0): time.sleep(1) + duration = float(self.totem.get_property('stream-length') / 1000) + timeout -= 1 # we also get a start time from the device targetoffset = float(duration * float(self.location[1])) position = float(self.totem.get_property('current-time') / 1000) @@ -90,10 +93,10 @@ class AirPlayTotemPlayer(AirPlayService): self.set_scrub(targetoffset) if (not self.totem.is_playing()): - self.totem.action_play() + gobject.idle_add(self.totem.action_play) del self.location self.location = None else: - self.totem.action_pause() + gobject.idle_add(self.totem.action_pause) -- cgit v1.1-32-gdbae