root / trunk / web / dojo / dojox / av / FLAudio.js @ 11
History | View | Annotate | Download (3.31 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.av.FLAudio"]){ |
9 |
dojo._hasResource["dojox.av.FLAudio"]=true; |
10 |
dojo.provide("dojox.av.FLAudio");
|
11 |
dojo.experimental("dojox.av.FLAudio");
|
12 |
dojo.require("dojox.embed.Flash");
|
13 |
dojo.require("dojox.timing.doLater");
|
14 |
dojo.declare("dojox.av.FLAudio",null,{id:"",initialVolume:0.7,initialPan:0,isDebug:false,statusInterval:200,_swfPath:dojo.moduleUrl("dojox.av","resources/audio.swf"),constructor:function(_1){ |
15 |
dojo.global.swfIsInHTML=function(){ |
16 |
return true; |
17 |
}; |
18 |
dojo.mixin(this,_1||{});
|
19 |
if(!this.id){ |
20 |
this.id="flaudio_"+new Date().getTime(); |
21 |
} |
22 |
this.domNode=dojo.doc.createElement("div"); |
23 |
dojo.style(this.domNode,{postion:"relative",width:"1px",height:"1px",top:"1px",left:"1px"}); |
24 |
dojo.body().appendChild(this.domNode);
|
25 |
this.init();
|
26 |
},init:function(){ |
27 |
this._subs=[];
|
28 |
this.initialVolume=this._normalizeVolume(this.initialVolume); |
29 |
var _2={path:this._swfPath.uri,width:"1px",height:"1px",minimumVersion:9,expressInstall:true,params:{wmode:"transparent"},vars:{id:this.id,autoPlay:this.autoPlay,initialVolume:this.initialVolume,initialPan:this.initialPan,statusInterval:this.statusInterval,isDebug:this.isDebug}}; |
30 |
this._sub("mediaError","onError"); |
31 |
this._sub("filesProgress","onLoadStatus"); |
32 |
this._sub("filesAllLoaded","onAllLoaded"); |
33 |
this._sub("mediaPosition","onPlayStatus"); |
34 |
this._sub("mediaEnd","onComplete"); |
35 |
this._sub("mediaMeta","onID3"); |
36 |
this._flashObject=new dojox.embed.Flash(_2,this.domNode); |
37 |
this._flashObject.onError=function(_3){ |
38 |
console.warn("Flash Error:",_3);
|
39 |
alert(_3); |
40 |
}; |
41 |
this._flashObject.onLoad=dojo.hitch(this,function(_4){ |
42 |
this.flashMedia=_4;
|
43 |
this.isPlaying=this.autoPlay; |
44 |
this.isStopped=!this.autoPlay; |
45 |
this.onLoad(this.flashMedia); |
46 |
}); |
47 |
},load:function(_5){ |
48 |
if(dojox.timing.doLater(this.flashMedia,this)){ |
49 |
return false; |
50 |
} |
51 |
if(!_5.url){
|
52 |
throw new Error("An url is required for loading media"); |
53 |
return false; |
54 |
}else{
|
55 |
_5.url=this._normalizeUrl(_5.url);
|
56 |
} |
57 |
this.flashMedia.load(_5);
|
58 |
return _5.url;
|
59 |
},doPlay:function(_6){ |
60 |
this.flashMedia.doPlay(_6);
|
61 |
},pause:function(_7){ |
62 |
this.flashMedia.pause(_7);
|
63 |
},stop:function(_8){ |
64 |
this.flashMedia.doStop(_8);
|
65 |
},setVolume:function(_9){ |
66 |
this.flashMedia.setVolume(_9);
|
67 |
},setPan:function(_a){ |
68 |
this.flashMedia.setPan(_a);
|
69 |
},getVolume:function(_b){ |
70 |
return this.flashMedia.getVolume(_b); |
71 |
},getPan:function(_c){ |
72 |
return this.flashMedia.getPan(_c); |
73 |
},getPosition:function(_d){ |
74 |
return this.flashMedia.getPosition(_d); |
75 |
},onError:function(_e){ |
76 |
console.warn("SWF ERROR:",_e);
|
77 |
},onLoadStatus:function(_f){ |
78 |
},onAllLoaded:function(){ |
79 |
},onPlayStatus:function(_10){ |
80 |
},onComplete:function(_11){ |
81 |
},onLoad:function(){ |
82 |
},onID3:function(evt){ |
83 |
},destroy:function(){ |
84 |
if(!this.flashMedia){ |
85 |
this._cons.push(dojo.connect(this,"onLoad",this,"destroy")); |
86 |
return;
|
87 |
} |
88 |
dojo.forEach(this._subs,function(s){ |
89 |
dojo.unsubscribe(s); |
90 |
}); |
91 |
dojo.forEach(this._cons,function(c){ |
92 |
dojo.disconnect(c); |
93 |
}); |
94 |
this._flashObject.destroy();
|
95 |
},_sub:function(_12,_13){ |
96 |
dojo.subscribe(this.id+"/"+_12,this,_13); |
97 |
},_normalizeVolume:function(vol){ |
98 |
if(vol>1){ |
99 |
while(vol>1){ |
100 |
vol*=0.1;
|
101 |
} |
102 |
} |
103 |
return vol;
|
104 |
},_normalizeUrl:function(_14){ |
105 |
if(_14&&_14.toLowerCase().indexOf("http")<0){ |
106 |
var loc=window.location.href.split("/"); |
107 |
loc.pop(); |
108 |
loc=loc.join("/")+"/"; |
109 |
_14=loc+_14; |
110 |
} |
111 |
return _14;
|
112 |
}}); |
113 |
} |