changeset 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 44491e963eee
files browser_side/radiocol.py
diffstat 1 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/radiocol.py	Tue Feb 04 17:52:12 2014 +0100
+++ b/browser_side/radiocol.py	Thu Jan 16 11:51:52 2014 +0100
@@ -28,6 +28,7 @@
 from pyjamas.ui.Hidden import Hidden
 from pyjamas.ui.HTML import HTML
 from pyjamas.ui.CaptionPanel import CaptionPanel
+from pyjamas.media.Audio import Audio
 from pyjamas import Window
 from pyjamas.Timer import Timer
 from __pyjamas__ import JS
@@ -163,10 +164,10 @@
             self.status.setText('')
 
 
-class Player(HTML):
+class Player(Audio):
 
     def __init__(self, player_id, metadata_panel):
-        HTML.__init__(self)
+        Audio.__init__(self)
         self._id = player_id
         self.metadata = metadata_panel
         self.timestamp = ""
@@ -174,7 +175,11 @@
         self.artist = ""
         self.album = ""
         self.filename = None
-        self.played = False  # True when song is playing/played, become False on preload
+        self.played = False  # True when the song is playing/has played, becomes False on preload
+        self.setAutobuffer(True)
+        self.setAutoplay(False)
+        self.setVisible(False)
+
 
     def preload(self, timestamp, filename, title, artist, album):
         """preload the song but doesn't play it"""
@@ -184,21 +189,21 @@
         self.artist = artist
         self.album = album
         self.played = False
-        self.setHTML('<audio id="%s" style="display: none" preload="auto" src="radiocol/%s" />' % (self._id, html_sanitize(filename)))
+        self.setSrc("radiocol/%s" % html_sanitize(filename))
         print "preloading %s in %s" % (title, self._id)
 
     def play(self, play=True):
-        """actually play the song"""
+        """Play or pause the song
+        @param play: set to True to play or to False to pause
+        """
         if play:
             self.played = True
             self.metadata.setTitle(self.title)
             self.metadata.setArtist(self.artist)
             self.metadata.setAlbum(self.album)
-
-        if play:  # JS only support constant strings
-            JS("""var player = top.document.getElementById(this._id); if (player) player.play();""")
+            Audio.play(self)
         else:
-            JS("""var player = top.document.getElementById(this._id); if (player) player.pause();""")
+            self.pause()
 
 
 class RadioColPanel(HorizontalPanel, ClickHandler):