Mercurial > libervia-web
changeset 287:7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 28 Nov 2013 21:43:12 +0100 |
parents | e76ec07be8e5 |
children | 7316a5696366 |
files | browser_side/radiocol.py public/libervia.css |
diffstat | 2 files changed, 36 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/radiocol.py Wed Nov 27 13:33:56 2013 +0100 +++ b/browser_side/radiocol.py Thu Nov 28 21:43:12 2013 +0100 @@ -143,7 +143,8 @@ def onSubmitComplete(self, event): result = event.getResults() if result == "OK": - self.setTemporaryStatus('[Your song has been added to queue]', "ok") + # the song can still be rejected (not readable, full queue...) + self.setTemporaryStatus('[Your song has been submitted to the radio]', "ok") elif result == "KO": self.setTemporaryStatus('[Something went wrong during your song upload]', "ko") else: @@ -157,14 +158,16 @@ HTML.__init__(self) self._id = player_id self.metadata = metadata_panel + self.timestamp = "" self.title = "" self.artist = "" self.album = "" self.filename = None self.played = False # True when song is playing/played, become False on preload - def preload(self, filename, title, artist, album): + def preload(self, timestamp, filename, title, artist, album): """preload the song but doesn't play it""" + self.timestamp = timestamp self.filename = filename self.title = title self.artist = artist @@ -173,17 +176,18 @@ self.setHTML('<audio id="%s" style="display: none" preload="auto" src="radiocol/%s" />' % (self._id, html_sanitize(filename))) print "preloading %s in %s" % (title, self._id) - def play(self): + def play(self, play=True): """actually play the song""" - self.played = True - self.metadata.setTitle(self.title) - self.metadata.setArtist(self.artist) - self.metadata.setAlbum(self.album) + if play: + self.played = True + self.metadata.setTitle(self.title) + self.metadata.setArtist(self.artist) + self.metadata.setAlbum(self.album) - JS(""" - var player = top.document.getElementById(this._id); - player.play(); - """) + if play: # JS only support constant strings + JS("""var player = top.document.getElementById(this._id); if (player) player.play();""") + else: + JS("""var player = top.document.getElementById(this._id); if (player) player.pause();""") class RadioColPanel(HorizontalPanel, ClickHandler): @@ -206,7 +210,7 @@ self.add(CaptionPanel("Controls", self.control_panel)) self.next_songs = [] - self.players = [Player("player_%d" % i, self.metadata_panel) for i in range(4)] + self.players = [Player("player_%d" % i, self.metadata_panel) for i in xrange(queue_data[1] + 1)] self.current_player = None for player in self.players: self.add(player) @@ -226,6 +230,7 @@ next_song.setStyleName("radiocol_next_song") self.next_songs.append(next_song) self.playlist_panel.append(next_song) + self.control_panel.updateStatus() def popNextSong(self): """Remove the first song of next songs list @@ -233,18 +238,27 @@ #FIXME: should check that the song we remove is the one we play next_song = self.next_songs.pop(0) self.playlist_panel.remove(next_song) + self.control_panel.updateStatus() def getQueueSize(self): return len(self.playlist_panel.getChildren()) - def radiocolPreload(self, filename, title, artist, album): + def radiocolCheckPreload(self, timestamp): + for player in self.players: + if player.timestamp == timestamp: + return False + return True + + def radiocolPreload(self, timestamp, filename, title, artist, album): + if not self.radiocolCheckPreload(timestamp): + return # song already preloaded preloaded = False for player in self.players: if not player.filename or \ (player.played and player != self.current_player): #if player has no file loaded, or it has already played its song #we use it to preload the next one - player.preload(filename, title, artist, album) + player.preload(timestamp, filename, title, artist, album) preloaded = True break if not preloaded: @@ -253,14 +267,17 @@ self.pushNextSong(title) def radiocolPlay(self, filename): + found = False for player in self.players: - if player.filename == filename: + if not found and player.filename == filename: player.play() self.popNextSong() self.current_player = player - self.control_panel.updateStatus() - return - print("WARNING: Song not found in queue, can't play it. This should not happen") + found = True + else: + player.play(False) # in case the previous player was not sync + if not found: + print("WARNING: Song not found in queue, can't play it. This should not happen") def radiocolNoUpload(self): self.control_panel.blockUpload()