Created
July 12, 2015 12:30
-
-
Save pachacamac/f3ba5354958fb9b138b4 to your computer and use it in GitHub Desktop.
simple html and js based audiobook player project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>AudiobookPlayer</title> | |
| <style> | |
| /*style here*/ | |
| </style> | |
| <script src="https://rawgit.com/kolber/audiojs/master/audiojs/audio.min.js"></script> | |
| <script> | |
| // reference: http://kolber.github.io/audiojs/docs/ | |
| var as, audio; | |
| audiojs.events.ready(function() { | |
| as = audiojs.createAll(); | |
| audio = as[0]; | |
| document.getElementById('audio').addEventListener('timeupdate', function(e){ | |
| console.log(e.target.currentSrc, e.target.currentTime); //TODO: remember position | |
| }); | |
| function relativeSeek(seconds){ | |
| audio.skipTo(audio.element.currentTime / audio.duration + seconds / audio.duration); | |
| } | |
| // loading | |
| document.getElementById('localFile').addEventListener('change', function(e){ audio.load(URL.createObjectURL(e.target.files[0])); }); | |
| document.getElementById('remoteFile').addEventListener('click', function(e){ audio.load(prompt('remote url')); }); | |
| // seeking | |
| document.getElementById('rewind').addEventListener('click', function(e){ relativeSeek(-10); }); | |
| document.getElementById('forward').addEventListener('click', function(e){ relativeSeek(10); }); | |
| document.getElementById('rewindMore').addEventListener('click', function(e){ relativeSeek(-60); }); | |
| document.getElementById('forwardMore').addEventListener('click', function(e){ relativeSeek(60); }); | |
| //audio.setVolume(0.75); | |
| //audio.skipTo(audio.element.currentTime / audio.duration - 0.01) | |
| //document.getElementById('file').addEventListener('') | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <!-- <audio src="http://example.com/audiobook.mp3"></audio> --> | |
| <!-- <audio id='audio' src="file:///home/user/audiobooks/audiobook.mp3"></audio> --> | |
| <audio id='audio'></audio> | |
| <p> | |
| <input type='button' id='rewindMore' value='<<'> | |
| <input type='button' id='rewind' value='<'> | |
| <input type='button' id='forward' value='>'> | |
| <input type='button' id='forwardMore' value='>>'> | |
| </p> | |
| <p> | |
| load local file: | |
| <input type='file' id='localFile'> | |
| </p> | |
| <p> | |
| <input type='button' id='remoteFile' value='load remote file'> | |
| </p> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment