summaryrefslogtreecommitdiffstats
path: root/airplay.py
diff options
context:
space:
mode:
Diffstat (limited to 'airplay.py')
-rw-r--r--airplay.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/airplay.py b/airplay.py
new file mode 100644
index 0000000..2493764
--- /dev/null
+++ b/airplay.py
@@ -0,0 +1,76 @@
1# -*- coding: utf-8 -*-
2
3import totem
4import platform
5import time
6from AirPlayService import AirPlayService
7
8class AirPlayPlugin (totem.Plugin):
9 def __init__ (self):
10 totem.Plugin.__init__ (self)
11 self.totem = None
12
13 def activate (self, totem_object):
14 self.service = AirPlayTotemPlayer(totem=totem_object,name="Totem on %s" % (platform.node()))
15
16 def deactivate (self, totem_object):
17 self.service.__del__()
18
19class AirPlayTotemPlayer(AirPlayService):
20 def __init__(self, totem, name=None, host="0.0.0.0", port=22555):
21 self.location = None
22 self.totem = totem
23 AirPlayService.__init__(self, name, host, port)
24
25 def __del__(self):
26 self.totem.action_stop()
27 AirPlayService.__del__(self)
28
29 # this returns current media duration and current seek time
30 def get_scrub(self):
31 # return self.totem.stream-length, self.totem.current-time
32 duration = float(self.totem.get_property('stream-length') / 1000)
33 position = float(self.totem.get_property('current-time') / 1000)
34 return duration, position
35
36 # this must seek to a certain time
37 def set_scrub(self, position):
38 if self.totem.is_seekable():
39 self.totem.action_seek_time(int(float(position) * 1000))
40
41 # this only sets the location and start position, it does not yet start to play
42 def play(self, location, position):
43 # start position is in percent
44 self.location = [location, position]
45
46 # stop the playback completely
47 def stop(self, info):
48 self.totem.action_stop()
49
50 # reverse HTTP to PTTH
51 def reverse(self, info):
52 pass
53
54 # playback rate, 0.0 - 1.0
55 def rate(self, speed):
56 if (int(float(speed)) >= 1):
57 if self.location is not None:
58 # start playback and loading of media
59 self.totem.add_to_playlist_and_play(self.location[0], "AirPlay Video", False)
60 # wait until stream-length is loaded and is not zero
61 duration = 0
62 while (int(duration) == 0):
63 duration = float(self.totem.get_property('stream-length') / 1000)
64 time.sleep(1)
65 # we also get a start time from the device, so seek to it
66 targetoffset = float(duration * float(self.location[1]))
67 self.set_scrub(targetoffset)
68
69 if (not self.totem.is_playing()):
70 self.totem.action_play()
71
72 del self.location
73 self.location = None
74 else:
75 self.totem.action_pause()
76