Commit 21541662 authored by Michael Murtaugh's avatar Michael Murtaugh
Browse files

Added separate html5audio delegate to map to a proper audio tag, and changed...

Added separate html5audio delegate to map to a proper audio tag, and changed OggAudio model to map to this
parent 799ec6bd
......@@ -529,6 +529,8 @@ add_delegate((function () {
tagstr += ">browser has no video tag support</video>";
videotag = $(tagstr).attr("src", o.src).appendTo(media.element).get(0);
/* Bind events */
$(videotag).bind("play", media._trigger("play"));
$(videotag).bind("pause", media._trigger("pause"));
......@@ -586,6 +588,86 @@ add_delegate((function () {
})());
add_delegate((function () {
var klass = {};
klass.name = "html5audio";
klass.sniff = function (url) {
var urlpat = /og(v|g)$/i;
return urlpat.test(url);
};
klass.init = function (media) {
var o = media.options;
var that = {name: klass.name};
var videotag = null;
// Init
var tagstr = "<audio";
if (o.controls) { tagstr += " controls"; }
if (o.autoplay) { tagstr += " autoplay"; }
if (o.autobuffer) { tagstr += " autobuffer"; }
tagstr += ">browser has no audio tag support</video>";
videotag = $(tagstr).attr("src", o.src).appendTo(media.element).get(0);
/* Bind events */
$(videotag).bind("play", media._trigger("play"));
$(videotag).bind("pause", media._trigger("pause"));
$(videotag).bind("ended", function () {
/* addressing a bug that the video tag seems to receive an ended event
* when a seek fails (seek beyond where it can read)
* so suppress ended events when duration is undefined
*/
if (that.getDuration()) media._trigger("ended");
});
// Export Required Methods
that.play = function () { videotag.play(); }
that.pause = function () { videotag.pause(); }
that.getPaused = function () { return videotag.paused; };
that.getCurrentTime = function () { return videotag.currentTime; }
that.seek = function (t) {
// videotag.currentTime = t;
var tries = 0;
function trytoseek () {
try {
// log("trying to setCurrentTime", t);
videotag.currentTime = t;
} catch (e) {
// log("retrying...", e);
tries += 1;
if (++tries >= 30*4) {
// log("setCurrentTime: giving up.");
return;
}
window.setTimeout(trytoseek, 250);
}
}
trytoseek();
};
that.getDuration = function (t) {
return videotag.duration;
}
that.destroy = function () {
if (videotag) {
$(videotag).remove();
videotag = null;
}
}
if (o._start) {
that.seek(o._start);
}
return that;
};
return klass;
})());
/**********************************/
/* YouTube delegate */
......
......@@ -454,7 +454,7 @@ class OggAudio (models.Model):
bitrate_display.short_description = "bitrate"
def delegate(self):
return "html5"
return "html5audio"
###############
# Sniffer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment