1 | define(['dojo', 'dijit', 'dijit/_Widget', 'dijit/_TemplatedMixin'],function(dojo, dijit, _Widget, _TemplatedMixin){ |
---|
2 | |
---|
3 | return dojo.declare("dojox.av.widget.Status", [_Widget, _TemplatedMixin], { |
---|
4 | // summary: |
---|
5 | // A Status widget to use with dojox.av.widget.Player |
---|
6 | // description: |
---|
7 | // Displays the name of the media file, and it's current status |
---|
8 | // (playing, paused, buffering, etc.) in the middle. Displays |
---|
9 | // the playhead time on the left and the duration on the right. |
---|
10 | |
---|
11 | templateString: dojo.cache("dojox.av.widget","resources/Status.html"), |
---|
12 | |
---|
13 | setMedia: function(/* Object */med){ |
---|
14 | // summary: |
---|
15 | // A common method to set the media in all Player widgets. |
---|
16 | // May do connections and initializations. |
---|
17 | |
---|
18 | this.media = med; |
---|
19 | dojo.connect(this.media, "onMetaData", this, function(data){ |
---|
20 | this.duration = data.duration; |
---|
21 | this.durNode.innerHTML = this.toSeconds(this.duration); |
---|
22 | }); |
---|
23 | dojo.connect(this.media, "onPosition", this, function(time){ |
---|
24 | this.timeNode.innerHTML = this.toSeconds(time); |
---|
25 | }); |
---|
26 | |
---|
27 | var cons = ["onMetaData", "onPosition", "onStart", "onBuffer", "onPlay", "onPaused", "onStop", "onEnd", "onError", "onLoad"]; |
---|
28 | dojo.forEach(cons, function(c){ |
---|
29 | dojo.connect(this.media, c, this, c); |
---|
30 | }, this); |
---|
31 | |
---|
32 | }, |
---|
33 | onMetaData: function(data){ |
---|
34 | this.duration = data.duration; |
---|
35 | this.durNode.innerHTML = this.toSeconds(this.duration); |
---|
36 | if(this.media.title){ |
---|
37 | this.title = this.media.title; |
---|
38 | }else{ |
---|
39 | var a = this.media.mediaUrl.split("/"); |
---|
40 | var b = a[a.length-1].split(".")[0]; |
---|
41 | this.title = b; |
---|
42 | } |
---|
43 | }, |
---|
44 | onBuffer: function(isBuffering){ |
---|
45 | this.isBuffering = isBuffering; |
---|
46 | console.warn("status onBuffer", this.isBuffering); |
---|
47 | if(this.isBuffering){ |
---|
48 | this.setStatus("buffering..."); |
---|
49 | }else{ |
---|
50 | this.setStatus("Playing"); |
---|
51 | } |
---|
52 | }, |
---|
53 | onPosition:function(time){ |
---|
54 | //console.log("onPosition:", time) |
---|
55 | // this.timeNode.innerHTML = this.toSeconds(time); |
---|
56 | }, |
---|
57 | onStart: function(){ |
---|
58 | this.setStatus("Starting"); |
---|
59 | }, |
---|
60 | onPlay: function(){ |
---|
61 | this.setStatus("Playing"); |
---|
62 | }, |
---|
63 | onPaused: function(){ |
---|
64 | this.setStatus("Paused"); |
---|
65 | }, |
---|
66 | onStop: function(){ |
---|
67 | this.setStatus("Stopped"); |
---|
68 | }, |
---|
69 | onEnd: function(){ |
---|
70 | this.setStatus("Stopped"); |
---|
71 | }, |
---|
72 | onError: function(evt){ |
---|
73 | console.log("status error:", evt) |
---|
74 | var msg = evt.info.code; |
---|
75 | if(msg == "NetStream.Play.StreamNotFound"){ |
---|
76 | msg = "Stream Not Found" |
---|
77 | } |
---|
78 | this.setStatus("ERROR: "+ msg, true); |
---|
79 | }, |
---|
80 | onLoad: function(){ |
---|
81 | this.setStatus("Loading..."); |
---|
82 | }, |
---|
83 | |
---|
84 | setStatus: function(str, isError){ |
---|
85 | if(isError){ |
---|
86 | dojo.addClass(this.titleNode, "statusError"); |
---|
87 | }else{ |
---|
88 | dojo.removeClass(this.titleNode, "statusError"); |
---|
89 | if(this.isBuffering){ |
---|
90 | str = "buffering..."; |
---|
91 | } |
---|
92 | } |
---|
93 | //console.log(this.titleNode, "title:",this.title, "str:",str) |
---|
94 | this.titleNode.innerHTML = '<span class="statusTitle">'+this.title+'</span> <span class="statusInfo">'+str+'</span>'; |
---|
95 | }, |
---|
96 | |
---|
97 | toSeconds: function(time){ |
---|
98 | var ts = time.toString() |
---|
99 | |
---|
100 | if(ts.indexOf(".")<0){ |
---|
101 | ts += ".00" |
---|
102 | }else if(ts.length - ts.indexOf(".")==2){ |
---|
103 | ts+="0" |
---|
104 | }else if(ts.length - ts.indexOf(".")>2){ |
---|
105 | ts = ts.substring(0, ts.indexOf(".")+3) |
---|
106 | } |
---|
107 | return ts; |
---|
108 | } |
---|
109 | |
---|
110 | }); |
---|
111 | |
---|
112 | }); |
---|