Mercurial > code > home > repos > light9
changeset 788:8d87a3528369
go button support
Ignore-this: e32b66cb39bf05a2fec5c91fdb7a7093
author | drewp@bigasterisk.com |
---|---|
date | Mon, 18 Jun 2012 01:13:18 +0000 |
parents | 603383733d7c |
children | ea8ca6502255 |
files | bin/ascoltami2 bin/gobutton light9/ascoltami/index.html light9/ascoltami/player.py light9/ascoltami/webapp.py |
diffstat | 5 files changed, 48 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/ascoltami2 Mon Jun 18 00:42:48 2012 +0000 +++ b/bin/ascoltami2 Mon Jun 18 01:13:18 2012 +0000 @@ -4,7 +4,7 @@ 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 @@ 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()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/gobutton Mon Jun 18 01:13:18 2012 +0000 @@ -0,0 +1,3 @@ +#!/bin/sh +# uri should be set from $LIGHT9_SHOW/config.n3 +exec curl --silent -d '' http://localhost:8040/go
--- a/light9/ascoltami/index.html Mon Jun 18 00:42:48 2012 +0000 +++ b/light9/ascoltami/index.html Mon Jun 18 01:13:18 2012 +0000 @@ -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>
--- a/light9/ascoltami/player.py Mon Jun 18 00:42:48 2012 +0000 +++ b/light9/ascoltami/player.py Mon Jun 18 01:13:18 2012 +0000 @@ -21,6 +21,7 @@ self.playStartTime = 0 self.lastWatchTime = 0 self.autoStopTime = 0 + self.lastSetSongUri = None self.onEOS = onEOS # before playbin2: @@ -57,14 +58,6 @@ 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 @@ 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 @@ 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 @@ 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()
--- a/light9/ascoltami/webapp.py Mon Jun 18 00:42:48 2012 +0000 +++ b/light9/ascoltami/webapp.py Mon Jun 18 01:13:18 2012 +0000 @@ -24,19 +24,22 @@ # 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 @@ 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 @@ r"/songs", "songs", r"/seekPlayOrPause", "seekPlayOrPause", r"/output", "output", + r"/go", "goButton", ) return web.application(urls, globals(), autoreload=False)