Mercurial > libervia-web
comparison browser_side/radiocol.py @ 341:31c105017d6b
browser_side: radiocol current song playback will jump to time when a user joins a running session
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 16 Jan 2014 11:51:52 +0100 |
parents | ce5b33f499c5 |
children | 30d03d9f07e4 |
comparison
equal
deleted
inserted
replaced
340:ce5b33f499c5 | 341:31c105017d6b |
---|---|
26 from pyjamas.ui.Button import Button | 26 from pyjamas.ui.Button import Button |
27 from pyjamas.ui.ClickListener import ClickHandler | 27 from pyjamas.ui.ClickListener import ClickHandler |
28 from pyjamas.ui.Hidden import Hidden | 28 from pyjamas.ui.Hidden import Hidden |
29 from pyjamas.ui.HTML import HTML | 29 from pyjamas.ui.HTML import HTML |
30 from pyjamas.ui.CaptionPanel import CaptionPanel | 30 from pyjamas.ui.CaptionPanel import CaptionPanel |
31 from pyjamas.media.Audio import Audio | |
31 from pyjamas import Window | 32 from pyjamas import Window |
32 from pyjamas.Timer import Timer | 33 from pyjamas.Timer import Timer |
33 from __pyjamas__ import JS | 34 from __pyjamas__ import JS |
34 | 35 |
35 from tools import html_sanitize | 36 from tools import html_sanitize |
161 else: | 162 else: |
162 Window.alert('Submit error: %s' % result) | 163 Window.alert('Submit error: %s' % result) |
163 self.status.setText('') | 164 self.status.setText('') |
164 | 165 |
165 | 166 |
166 class Player(HTML): | 167 class Player(Audio): |
167 | 168 |
168 def __init__(self, player_id, metadata_panel): | 169 def __init__(self, player_id, metadata_panel): |
169 HTML.__init__(self) | 170 Audio.__init__(self) |
170 self._id = player_id | 171 self._id = player_id |
171 self.metadata = metadata_panel | 172 self.metadata = metadata_panel |
172 self.timestamp = "" | 173 self.timestamp = "" |
173 self.title = "" | 174 self.title = "" |
174 self.artist = "" | 175 self.artist = "" |
175 self.album = "" | 176 self.album = "" |
176 self.filename = None | 177 self.filename = None |
177 self.played = False # True when song is playing/played, become False on preload | 178 self.played = False # True when the song is playing/has played, becomes False on preload |
179 self.setAutobuffer(True) | |
180 self.setAutoplay(False) | |
181 self.setVisible(False) | |
182 | |
178 | 183 |
179 def preload(self, timestamp, filename, title, artist, album): | 184 def preload(self, timestamp, filename, title, artist, album): |
180 """preload the song but doesn't play it""" | 185 """preload the song but doesn't play it""" |
181 self.timestamp = timestamp | 186 self.timestamp = timestamp |
182 self.filename = filename | 187 self.filename = filename |
183 self.title = title | 188 self.title = title |
184 self.artist = artist | 189 self.artist = artist |
185 self.album = album | 190 self.album = album |
186 self.played = False | 191 self.played = False |
187 self.setHTML('<audio id="%s" style="display: none" preload="auto" src="radiocol/%s" />' % (self._id, html_sanitize(filename))) | 192 self.setSrc("radiocol/%s" % html_sanitize(filename)) |
188 print "preloading %s in %s" % (title, self._id) | 193 print "preloading %s in %s" % (title, self._id) |
189 | 194 |
190 def play(self, play=True): | 195 def play(self, play=True): |
191 """actually play the song""" | 196 """Play or pause the song |
197 @param play: set to True to play or to False to pause | |
198 """ | |
192 if play: | 199 if play: |
193 self.played = True | 200 self.played = True |
194 self.metadata.setTitle(self.title) | 201 self.metadata.setTitle(self.title) |
195 self.metadata.setArtist(self.artist) | 202 self.metadata.setArtist(self.artist) |
196 self.metadata.setAlbum(self.album) | 203 self.metadata.setAlbum(self.album) |
197 | 204 Audio.play(self) |
198 if play: # JS only support constant strings | |
199 JS("""var player = top.document.getElementById(this._id); if (player) player.play();""") | |
200 else: | 205 else: |
201 JS("""var player = top.document.getElementById(this._id); if (player) player.pause();""") | 206 self.pause() |
202 | 207 |
203 | 208 |
204 class RadioColPanel(HorizontalPanel, ClickHandler): | 209 class RadioColPanel(HorizontalPanel, ClickHandler): |
205 | 210 |
206 def __init__(self, parent, referee, player_nick, players, queue_data): | 211 def __init__(self, parent, referee, player_nick, players, queue_data): |