root / trunk / web / dojo / dojox / av / _Media.js
History | View | Annotate | Download (3.02 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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._Media"]){ |
||
9 | dojo._hasResource["dojox.av._Media"]=true; |
||
10 | dojo.provide("dojox.av._Media");
|
||
11 | dojo.declare("dojox.av._Media",null,{mediaUrl:"",initialVolume:1,autoPlay:false,bufferTime:2000,minBufferTime:300,updateTime:100,id:"",isDebug:false,percentDownloaded:0,_flashObject:null,flashMedia:null,_initStatus:function(){ |
||
12 | this.status="ready"; |
||
13 | dojo.connect(this,"onPosition",this,"_figureStatus"); |
||
14 | },getTime:function(){ |
||
15 | return this.flashMedia.getTime(); |
||
16 | },onLoad:function(_1){ |
||
17 | },onDownloaded:function(_2){ |
||
18 | },onClick:function(_3){ |
||
19 | },onSwfSized:function(_4){ |
||
20 | },onMetaData:function(_5,_6){ |
||
21 | this.duration=_5.duration;
|
||
22 | },onPosition:function(_7){ |
||
23 | },onStart:function(_8){ |
||
24 | },onPlay:function(_9){ |
||
25 | },onPause:function(_a){ |
||
26 | },onEnd:function(_b){ |
||
27 | },onStop:function(){ |
||
28 | },onBuffer:function(_c){ |
||
29 | this.isBuffering=_c;
|
||
30 | },onError:function(_d,_e){ |
||
31 | console.warn("ERROR-"+_d.type.toUpperCase()+":",_d.info.code," - URL:",_e); |
||
32 | },onStatus:function(_f){ |
||
33 | },onPlayerStatus:function(_10){ |
||
34 | },onResize:function(){ |
||
35 | },_figureStatus:function(){ |
||
36 | var pos=this.getTime(); |
||
37 | if(this.status=="stopping"){ |
||
38 | this.status="stopped"; |
||
39 | this.onStop(this._eventFactory()); |
||
40 | }else{
|
||
41 | if(this.status=="ending"&&pos==this._prevPos){ |
||
42 | this.status="ended"; |
||
43 | this.onEnd(this._eventFactory()); |
||
44 | }else{
|
||
45 | if(this.duration&&pos>this.duration-0.5){ |
||
46 | this.status="ending"; |
||
47 | }else{
|
||
48 | if(pos===0){ |
||
49 | if(this.status=="ready"){ |
||
50 | }else{
|
||
51 | this.status="stopped"; |
||
52 | if(this._prevStatus!="stopped"){ |
||
53 | this.onStop(this._eventFactory()); |
||
54 | } |
||
55 | } |
||
56 | }else{
|
||
57 | if(this.status=="ready"){ |
||
58 | this.status="started"; |
||
59 | this.onStart(this._eventFactory()); |
||
60 | this.onPlay(this._eventFactory()); |
||
61 | }else{
|
||
62 | if(this.isBuffering){ |
||
63 | this.status="buffering"; |
||
64 | }else{
|
||
65 | if(this.status=="started"||(this.status=="playing"&&pos!=this._prevPos)){ |
||
66 | this.status="playing"; |
||
67 | }else{
|
||
68 | if(!this.isStopped&&this.status=="playing"&&pos==this._prevPos){ |
||
69 | this.status="paused"; |
||
70 | console.warn("pause",pos,this._prevPos); |
||
71 | if(this.status!=this._prevStatus){ |
||
72 | this.onPause(this._eventFactory()); |
||
73 | } |
||
74 | }else{
|
||
75 | if((this.status=="paused"||this.status=="stopped")&&pos!=this._prevPos){ |
||
76 | this.status="started"; |
||
77 | this.onPlay(this._eventFactory()); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | this._prevPos=pos;
|
||
88 | this._prevStatus=this.status; |
||
89 | this.onStatus(this.status); |
||
90 | },_eventFactory:function(){ |
||
91 | var evt={status:this.status}; |
||
92 | return evt;
|
||
93 | },_sub:function(_11,_12){ |
||
94 | dojo.subscribe(this.id+"/"+_11,this,_12); |
||
95 | },_normalizeVolume:function(vol){ |
||
96 | if(vol>1){ |
||
97 | while(vol>1){ |
||
98 | vol*=0.1;
|
||
99 | } |
||
100 | } |
||
101 | return vol;
|
||
102 | },_normalizeUrl:function(_13){ |
||
103 | if(_13&&(_13.toLowerCase().indexOf("http")<0||_13.indexOf("/")==0)){ |
||
104 | var loc=window.location.href.split("/"); |
||
105 | loc.pop(); |
||
106 | loc=loc.join("/")+"/"; |
||
107 | _13=loc+_13; |
||
108 | } |
||
109 | return _13;
|
||
110 | },destroy:function(){ |
||
111 | if(!this.flashMedia){ |
||
112 | this._cons.push(dojo.connect(this,"onLoad",this,"destroy")); |
||
113 | return;
|
||
114 | } |
||
115 | dojo.forEach(this._subs,function(s){ |
||
116 | dojo.unsubscribe(s); |
||
117 | }); |
||
118 | dojo.forEach(this._cons,function(c){ |
||
119 | dojo.disconnect(c); |
||
120 | }); |
||
121 | this._flashObject.destroy();
|
||
122 | }}); |
||
123 | } |