X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=web%2Fsongbook.js;fp=web%2Fsongbook.js;h=85a4b18abd6202c354dd2af9411dfa8b3760d3f5;hb=4b532d27ad4ad7d71bb190f7974b3129ee114b22;hp=0000000000000000000000000000000000000000;hpb=f197828f66bca9e6594d3fbd8e255d476648c34e;p=songbook.git diff --git a/web/songbook.js b/web/songbook.js new file mode 100644 index 0000000..85a4b18 --- /dev/null +++ b/web/songbook.js @@ -0,0 +1,72 @@ +// Javascript functions for controling audio +starttime = null; +endtime = null; + +spacebar = 32; +return2start = 82; +backfewsecs = 66; +forwardfewsecs = 70; +seta = 65; +cleara = 67; +howmanysecs = 10; + +window.onload = function() { + song = document.getElementById('song'); + + starttime = song.currentTime; + endtime = song.duration; + body = document.getElementsByTagName('body')[0] + + body.onkeydown = + function(e) { + var ev = e || event; + if (ev.keyCode == spacebar) { + if (song.paused) { + playing = false; + } else { + playing = true; + } // if + + if (playing) { + song.pause(); + playing = false; + } else { + if (starttime != 0) { + song.currentTime = starttime + } // if + + song.play(); + playing = true; + } // if + + e.preventDefault(); + return; + } else if (ev.keyCode == return2start) { + if (starttime != null) { + song.currentTime = starttime; + } else { + song.currentTime = 0; + } // if + + return; + } else if (ev.keyCode == backfewsecs) { + song.currentTime -= howmanysecs; + song.play() + + return; + } else if (ev.keyCode == forwardfewsecs) { + song.currentTime += howmanysecs; + song.play(); + + return; + } else if (ev.keyCode == seta) { + starttime = song.currentTime; + + return; + } else if (ev.keyCode == cleara) { + starttime = 0; + + return; + } // if + } // function + } // getElementByTagName \ No newline at end of file