1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
2.8 KiB

/*jslint laxbreak:true */
/*jslint laxcomma:true */
/*jslint loopfunc:true */
/*jslint strict:true */
/*jslint browser:true */
/*jslint devel:true */
define([
"underscore"
, "jquery"
, "toolbox"
, "backbone"
]
, function (
_
, $
, Toolbox
, Backbone
) {
"use strict";
var WebAudio = Toolbox.Base.extend(_.extend({
_defaultOpts: {
autoplay: "autoplay"
, preload: "auto"
, controls: false
, loop: false
, src: ""
}
, obj: new Audio()
, $obj: null
, constructor: function () {
var that = this
;
_.bindAll(this
// Public
, "loadMedia"
// Private
, "_bindAudio"
// Events
, "__audioProgress"
, "__audioError"
, "__audioPause"
, "__audioPlay"
, "__audioTimeUpdate"
, "__audioLoadStart"
, "__audioCanPlay"
, "__audioEnded"
);
that.$obj = $(that.obj);
that.obj.attributes = _.extend({}, that.obj.attributes, that._defaultOpts);
return that;
}
/**
* PUBLIC
**/
, loadMedia: function (uri) {
var that = this
;
that.obj.stop();
}
/**
* PRIVATE
**/
, _bindAudio: function () {
var that = this
;
that.$obj.unbind();
that.$obj.on("loadstart", that.__audioLoadStart);
that.$obj.on("progress", that.__audioProgress);
//that.$obj.on("suspend", that.__audioSuspend);
//that.$obj.on("abort", that.__audioAbort);
that.$obj.on("error", that.__audioError);
//that.$obj.on("emptied", that.__audioEmptied);
//that.$obj.on("stalled", that.__audioStalled);
that.$obj.on("pause", that.__audioPause);
that.$obj.on("play", that.__audioPlay);
//that.$obj.on("loadedmetadata", that.__audioLoadedMetaData);
//that.$obj.on("loadeddata", that.__audioLoadedData);
//that.$obj.on("waiting", that.__audioWaiting);
//that.$obj.on("playing", that.__audioPlaying);
that.$obj.on("canplay", that.__audioCanPlay);
//that.$obj.on("canplaythrough", that.__audioCanPlayThrough);
//that.$obj.on("seeking", that.__audioSeeking);
//that.$obj.on("seeked", that.__audioSeeked);
that.$obj.on("timeupdate", that.__audioTimeUpdate);
that.$obj.on("ended", that.__audioEnded);
//that.$obj.on("ratechange", that.__audioRateChanged);
//that.$obj.on("durationchange", that.__audioDurationChange);
//that.$obj.on("volumechange", that.__audioVolumeChange);
}
/**
* EVENTS
**/
, __audioProgress: function (event) {
}
, __audioError: function (event) {
}
, __audioPause: function (event) {
var that = this
;
}
, __audioPlay: function (event) {
var that = this
;
}
, __audioTimeUpdate: function (event) {
var that = this
;
}
, __audioLoadStart: function (event) {
var that = this
;
}
, __audioCanPlay: function (event) {
var that = this
;
}
, __audioEnded: function (event) {
var that = this
;
}
}, Backbone.Events));
return WebAudio;
});