File: media/LSound.js
/** @language english
* <p>This class creates a LSound object.</p>
* <p>When the browser does not support Web Audio Api or set LGlobal.webAudio = false, LSound will automatically inherit LMedia object.</p>
* <p>When LSound inherited LMedia, if use the ios browser,must loading audio files in the click event, and only allow one audio file to play at a time.</p>
* @class LSound(LMedia)
* @extends LMedia
* @constructor
* @example
* var backLayer;
* var sound;
* function main () {
* backLayer = new LSprite();
* addChild(backLayer);
* sound = new LSound();
* ......
* backLayer.addEventListener(LMouseEvent.MOUSE_UP,onup);
* }
* function onup (e) {
* ......
* var url = "./sample.";
* sound.load(url+"mp3,"+url+"ogg,"+url+"wav");
* sound.addEventListener(LEvent.COMPLETE,loadOver);
* }
* function loadOver (e) {
* sound.play();
* }
* @examplelink <p><a href="../../../api/LSound/LMedia.html" target="_blank">Try it »</a></p>
* @since 1.7.0
* @public
*/
/** @language english
* <p>The browser supports the Web Audio.</p>
* @property LSound.webAudioEnabled
* @type Boolean
* @static
* @since 1.9.0
* @public
*/
/*LSound.webAudioEnabled = false;*/
/** @language english
* <p>This class creates a LSound object.</p>
* <p>When the browser does support Web Audio Api and set LGlobal.webAudio = true(default is true), LSound will automatically inherit LWebAudio object.</p>
* <p>When LSound inherited LWebAudio, the audio files can be loaded without the click event, but playing audio must in clicke event.</p>
* <p>When LSound inherited LWebAudio, allow multiple audio files to play at a time.</p>
* @class LSound(LWebAudio)
* @extends LWebAudio
* @constructor
* @example
* var backLayer;
* var sound;
* function main () {
* backLayer = new LSprite();
* addChild(backLayer);
* sound = new LSound();
* ......
* var url = "./sample.";
* sound.load(url+"mp3,"+url+"ogg,"+url+"wav");
* sound.addEventListener(LEvent.COMPLETE,loadOver);
* }
* function onup (e) {
* ......
* sound.play();
* }
* function loadOver (e) {
* backLayer.addEventListener(LMouseEvent.MOUSE_UP,onup);
* }
* @examplelink <p><a href="../../../api/LSound/LWebAudio.html" target="_blank">Try it »</a></p>
* @since 1.9.0
* @public
*/
var LSound = (function () {
function LSound (u) {
var s = this;
s.type = "LSound";
s._type="audio";
if (LSound.webAudioEnabled && LGlobal.webAudio) {
LExtends(s, LWebAudio, []);
} else {
LExtends(s, LMedia, []);
s.data = new Audio();
s.data.loop = false;
s.data.autoplay = false;
}
if (u) {
s.load(u);
}
}
LSound.TYPE_SOUND = "sound";
/** @language english
* <p>The browser supports the Web Audio.</p>
* @property LSound.webAudioEnabled
* @type Boolean
* @static
* @since 1.9.0
* @public
*/
LSound.webAudioEnabled = false;
var protocol = location.protocol;
if (protocol == "http:" || protocol == "https:") {
if (typeof webkitAudioContext !== UNDEFINED) {
try {
LWebAudio._context = new webkitAudioContext();
} catch (e) {
}
} else if (typeof AudioContext !== UNDEFINED) {
try {
LWebAudio._context = new AudioContext();
} catch (e) {
}
}
if (LWebAudio._context) {
LWebAudio.container.push(LWebAudio._context);
LSound.webAudioEnabled = true;
}
}
LSound.Container = {
ll_save : 0,
time : 0,
list : [],
ll_show : function () {
var c = LSound.Container;
var t = (new Date()).getTime();
c.time = t - (c.ll_save ? c.ll_save : t);
c.ll_save = t;
var l = c.list;
for (var i = l.length; i >= 0; i--) {
if (l[i]) {
l[i].ll_check();
}
}
},
add : function (obj) {
if (LSound.Container.list.indexOf(obj) >= 0) {
return;
}
LSound.Container.list.push(obj);
},
remove : function (obj) {
var l = LSound.Container.list;
for (var i = l.length; i >= 0; i--) {
if (l[i].objectIndex == obj.objectIndex) {
l.splice(i,1);
break;
}
}
}
};
LGlobal.childList.push(LSound.Container);
return LSound;
})();