This commit is contained in:
libccy 2015-05-16 22:18:03 +08:00
parent 4ead79290f
commit 1e7dcfbc91
1 changed files with 24 additions and 13 deletions

View File

@ -5059,14 +5059,10 @@ window.play={};
version:0.912, version:0.912,
playAudio:function(){ playAudio:function(){
var str=''; var str='';
var onerror=null;
for(var i=0;i<arguments.length;i++){ for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]==='string'||typeof arguments[i]=='number'){ if(typeof arguments[i]==='string'||typeof arguments[i]=='number'){
str+='/'+arguments[i]; str+='/'+arguments[i];
} }
else if(typeof arguments[i]==='function'){
onerror=arguments[i];
}
} }
var audio=document.createElement('audio'); var audio=document.createElement('audio');
audio.autoplay=true; audio.autoplay=true;
@ -5076,11 +5072,12 @@ window.play={};
this.remove(); this.remove();
}); });
audio.onerror=function(){ audio.onerror=function(){
if(onerror){ if(this._changed){
onerror.call(this); this.remove();
} }
else{ else{
this.remove(); this.src='audio'+str+'.ogg';
this._changed=true;
} }
}; };
ui.window.appendChild(audio); ui.window.appendChild(audio);
@ -5094,13 +5091,27 @@ window.play={};
audio.addEventListener('ended',function(){ audio.addEventListener('ended',function(){
this.remove(); this.remove();
}); });
audio._changed=1;
audio.onerror=function(){ audio.onerror=function(){
if(this._changed){ switch(this._changed){
this.remove(); case 1:{
} audio.src=str+name+'.ogg';
else{ this._changed=2;
this.src=str+name+Math.ceil(Math.random()*2)+'.mp3'; break;
this._changed=true; }
case 2:{
audio.src=str+name+Math.ceil(Math.random()*2)+'.mp3';
this._changed=3;
break;
}
case 3:{
audio.src=str+name+Math.ceil(Math.random()*2)+'.ogg';
this._changed=4;
break;
}
default:{
this.remove();
}
} }
}; };
ui.window.appendChild(audio); ui.window.appendChild(audio);