source: Dev/branches/rest-dojo-ui/client/dojox/av/widget/Status.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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