Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
// From: // http://angg.twu.net/blogme3/html5-audio.js.html // http://angg.twu.net/blogme3/html5-audio.js // (find-blogme3 "html5-audio.js") // Author: Eduardo Ochs <eduardoochs@gmail.com> // Version: 2013dec09 // // (find-2a '(find-fline "html5-audio.js") '(find-fline "html5-audio-mini.js")) // (find-tkdiff "html5-audio.js" "html5-audio-mini.js") // http://angg.twu.net/2013-petropolis.html // http://angg.twu.net/html5-audio.html // (find-TH "2013-petropolis") // (find-TH "html5-audio") // // http://html5doctor.com/native-audio-in-the-browser/ // (find-udfile "librhino-java-doc/examples/jsdoc.js") // toseconds = function (t) { if (typeof(t) == "number") { return t; } var a = "0:00:00"; var b = a.substr(0, a.length - t.length) + t; var h = b.substr(0, 1); var mm = b.substr(2, 2); var ss = b.substr(5, 2); return h*3600+mm*60+ss*1; } function audios () { return document.getElementsByTagName("audio"); } function audio (n) { return audios()[n|0]; } function playat (n, t) { audio(n).currentTime = toseconds(t); audio(n).play(); } function naudios () { return audios().length; } function audiosdo (f) { for (var i=0; i < naudios(); i++) f(audio(i)); } function pauseall () { audiosdo(function (a) { a.pause(); }); } function pl_ (n, t) { pauseall(); playat(n, t); } function kpl_(n, e) { if (!e) e = window.event; if (e.keyCode == 13) pl_(n, e.target.value); if (e.keyCode == 32) { pauseall(); e.preventDefault(); } } function pla(t) { pl_(0, t); } function plb(t) { pl_(1, t); } function kpla(t) { kpl_(0, t); } function kplb(t) { kpl_(1, t); } href0 = function (tgt, text) { return '<a href="'+tgt+'">'+text+'</a>'; } href = function (tgt, text) { return tgt ? href0(tgt, text) : text; } jref = function (code, text) { return href('javascript:'+code, text); } time_re = /[0-9]?[0-9]:[0-9][0-9](:[0-9][0-9])?/g; seekbox = function (F, T) { return '<input size=8 value="'+T+'" onkeydown="'+F+'()">'; } ptime0 = function (G, T) { return jref(G+"('"+T+"')", T); } ptime = function (G, T) { return "("+jref(G+"('"+T+"')", T)+")"; } seekboxptime = function (F, G, T) { return seekbox(F, T)+" "+ptime(G, T) } my_activate = function (elt, f) { elt.origtext = elt.origtext || elt.innerText; elt.innerHTML = f(elt.origtext); } my_activate_id = function (id, f) { my_activate(document.getElementById(id), f); } function boxptimepla (t) { return seekboxptime("kpla", "pla", t); } function boxptimeplb (t) { return seekboxptime("kplb", "plb", t); } function rboxptimepla (str) { return str.replace(time_re, boxptimepla); } function rboxptimeplb (str) { return str.replace(time_re, boxptimeplb); } function activate_audio_links_a (id) { my_activate_id(id, rboxptimepla); } function activate_audio_links_b (id) { my_activate_id(id, rboxptimeplb); } /* See: (find-blogme3 "anggdefs.lua" "html5-audio") Typical usage: (find-TH "tmp") <audio preload="auto" controls> <source src="2013dec04-aduff.mp3"> </audio> <pre id="mypre2"> 0:00 foo 1:23 bar </pre> <script src="../blogme3/html5-audio.js"></script> <script> activate_audio_links_a("mypre2") </script> */