Changeset - 8d87a3528369
[Not reviewed]
default
0 4 1
drewp@bigasterisk.com - 13 years ago 2012-06-18 01:13:18
drewp@bigasterisk.com
go button support
Ignore-this: e32b66cb39bf05a2fec5c91fdb7a7093
5 files changed with 48 insertions and 27 deletions:
0 comments (0 inline, 0 general)
bin/ascoltami2
Show inline comments
 
@@ -4,7 +4,7 @@ from rdflib import URIRef
 
sys.path.append(".")
 
from light9.ascoltami.player import Player
 
from light9.ascoltami.playlist import Playlist, NoSuchSong
 
from light9.ascoltami.webapp import makeWebApp
 
from light9.ascoltami.webapp import makeWebApp, songUri, songLocation
 
from light9 import networking, showconfig
 

	
 

	
 
@@ -33,14 +33,14 @@ class App:
 
        self.player.pause()
 
        self.player.seek(0)
 

	
 
        # stop here for now- no go-button behavior
 
        return
 
        thisSongUri = songUri(graph, URIRef(song))
 

	
 
        try:
 
            nextSong = self.playlist.nextSong(song)
 
            nextSong = self.playlist.nextSong(thisSongUri)
 
        except NoSuchSong: # we're at the end of the playlist
 
            return
 

	
 
        self.player.setSong(nextSong, play=False)
 
        self.player.setSong(songLocation(graph, nextSong), play=False)
 

	
 
if __name__ == "__main__":
 
    logging.basicConfig()
bin/gobutton
Show inline comments
 
new file 100644
 
#!/bin/sh
 
# uri should be set from $LIGHT9_SHOW/config.n3
 
exec curl --silent -d '' http://localhost:8040/go
light9/ascoltami/index.html
Show inline comments
 
@@ -119,7 +119,7 @@
 
	$.post("time", tojs({t: currentDuration - times.post, resume: true}))
 
    });
 
    $("#cmd-go").click(function () {
 
	// todo
 
	$.post("go");
 
    });
 
    $("#cmd-out0").click(function () { $.post("output", tojs({sink: "0"})); })
 
    $("#cmd-out1").click(function () { $.post("output", tojs({sink: "1"})); })
 
@@ -159,4 +159,4 @@
 

	
 

	
 
  </body>
 
</html>
 
\ No newline at end of file
 
</html>
light9/ascoltami/player.py
Show inline comments
 
@@ -21,6 +21,7 @@ class Player(object):
 
        self.playStartTime = 0
 
        self.lastWatchTime = 0
 
        self.autoStopTime = 0
 
        self.lastSetSongUri = None
 
        self.onEOS = onEOS
 
        
 
        # before playbin2:
 
@@ -57,14 +58,6 @@ class Player(object):
 
                log.info("autostop")
 
                self.pause()
 

	
 
                # new EOS logic above should be better
 
            ## if not self.onEOS:
 
            ##     if self.isPlaying() and t >= self.duration() - .2:
 
            ##         # i don't expect to hit dur exactly with this
 
            ##         # polling. What would be better would be to watch for
 
            ##         # the EOS signal and react to that
 
            ##         self.onEOS(self.getSong())
 

	
 
            self.lastWatchTime = t
 
        except:
 
            traceback.print_exc()
 
@@ -85,6 +78,7 @@ class Player(object):
 
        self.pipeline.set_state(gst.STATE_READY)
 
        self.preload(songLoc)
 
        self.pipeline.set_property("uri", songLoc)
 
        self.lastSetSongUri = songLoc
 
        # todo: don't have any error report yet if the uri can't be read
 
        if play:
 
            self.pipeline.set_state(gst.STATE_PLAYING)
 
@@ -92,7 +86,8 @@ class Player(object):
 

	
 
    def getSong(self):
 
        """Returns the URI of the current song."""
 
        return self.playbin.get_property("uri")
 
        # even the 'uri' that I just set isn't readable yet
 
        return self.playbin.get_property("uri") or self.lastSetSongUri
 

	
 
    def preload(self, songPath):
 
        """
 
@@ -129,12 +124,16 @@ class Player(object):
 
    def pause(self):
 
        self.pipeline.set_state(gst.STATE_PAUSED)
 

	
 
    def isAutostopped(self):
 
        """
 
        are we stopped at the autostop time?
 
        """
 
        pos = self.currentTime()
 
        autoStop = self.duration() - self.autoStopOffset
 
        return not self.isPlaying() and abs(pos - autoStop) < 1 # i've seen .4 difference here
 

	
 
    def resume(self):
 
        self.pipeline.set_state(gst.STATE_PLAYING)
 
        pos = self.currentTime()
 
        autoStop = self.duration() - self.autoStopOffset
 
        if abs(pos - autoStop) < .01:
 
            self.releaseAutostop()
 

	
 
    def setupAutostop(self):
 
        dur = self.duration()
light9/ascoltami/webapp.py
Show inline comments
 
@@ -24,19 +24,22 @@ class root(object):
 
        # times into the page
 
        return render.index(host=socket.gethostname())
 

	
 
def playerSongUri(graph, player):
 
    """or None"""
 
    
 
    playingLocation = player.getSong()
 
    if playingLocation:
 
        return songUri(graph, URIRef(playingLocation))
 
    else:
 
        return None
 

	
 
class timeResource(object):
 
    def GET(self):
 
        player = app.player
 
        graph = app.graph
 

	
 
        playingLocation = player.getSong()
 
        if playingLocation:
 
            song = songUri(graph, URIRef(playingLocation))
 
        else:
 
            song = None
 
        web.header("content-type", "application/json")
 
        return json.dumps({
 
            "song" : song,
 
            "song" : playerSongUri(graph, player),
 
            "started" : player.playStartTime,
 
            "duration" : player.duration(),
 
            "playing" : player.isPlaying(),
 
@@ -98,6 +101,21 @@ class output(object):
 
        d = json.loads(web.data())
 
        subprocess.check_call(["bin/movesinks", str(d['sink'])])
 

	
 
class goButton(object):
 
    def POST(self):
 
        """
 
        if music is playing, this silently does nothing.
 
        """
 
        graph, player = app.graph, app.player
 

	
 
        if player.isPlaying():
 
            pass
 
        else:
 
            player.resume()
 
            
 
        web.header("content-type", "text/plain")
 
        return "ok"
 

	
 
def makeWebApp(theApp):
 
    global app
 
    app = theApp
 
@@ -108,6 +126,7 @@ def makeWebApp(theApp):
 
            r"/songs", "songs",
 
            r"/seekPlayOrPause", "seekPlayOrPause",
 
            r"/output", "output",
 
            r"/go", "goButton",
 
            )
 

	
 
    return web.application(urls, globals(), autoreload=False)
0 comments (0 inline, 0 general)