gyorgy@0
|
1 (function($) {
|
gyorgy@0
|
2 // progress/loaded bar
|
gyorgy@0
|
3 MediaElementPlayer.prototype.buildprogress = function(player, controls, layers, media) {
|
gyorgy@0
|
4
|
gyorgy@0
|
5 $('<div class="mejs-time-rail">'+
|
gyorgy@0
|
6 '<span class="mejs-time-total">'+
|
gyorgy@0
|
7 '<span class="mejs-time-loaded"></span>'+
|
gyorgy@0
|
8 '<span class="mejs-time-current"></span>'+
|
gyorgy@0
|
9 '<span class="mejs-time-handle"></span>'+
|
gyorgy@0
|
10 '<span class="mejs-time-float">' +
|
gyorgy@0
|
11 '<span class="mejs-time-float-current">00:00</span>' +
|
gyorgy@0
|
12 '<span class="mejs-time-float-corner"></span>' +
|
gyorgy@0
|
13 '</span>'+
|
gyorgy@0
|
14 '</span>'+
|
gyorgy@0
|
15 '</div>')
|
gyorgy@0
|
16 .appendTo(controls);
|
gyorgy@0
|
17
|
gyorgy@0
|
18 var
|
gyorgy@0
|
19 t = this,
|
gyorgy@0
|
20 total = controls.find('.mejs-time-total'),
|
gyorgy@0
|
21 loaded = controls.find('.mejs-time-loaded'),
|
gyorgy@0
|
22 current = controls.find('.mejs-time-current'),
|
gyorgy@0
|
23 handle = controls.find('.mejs-time-handle'),
|
gyorgy@0
|
24 timefloat = controls.find('.mejs-time-float'),
|
gyorgy@0
|
25 timefloatcurrent = controls.find('.mejs-time-float-current'),
|
gyorgy@0
|
26 handleMouseMove = function (e) {
|
gyorgy@0
|
27 // mouse position relative to the object
|
gyorgy@0
|
28 var x = e.pageX,
|
gyorgy@0
|
29 offset = total.offset(),
|
gyorgy@0
|
30 width = total.outerWidth(),
|
gyorgy@0
|
31 percentage = 0,
|
gyorgy@0
|
32 newTime = 0;
|
gyorgy@0
|
33
|
gyorgy@0
|
34
|
gyorgy@0
|
35 if (x > offset.left && x <= width + offset.left && media.duration) {
|
gyorgy@0
|
36 percentage = ((x - offset.left) / width);
|
gyorgy@0
|
37 newTime = (percentage <= 0.02) ? 0 : percentage * media.duration;
|
gyorgy@0
|
38
|
gyorgy@0
|
39 // seek to where the mouse is
|
gyorgy@0
|
40 if (mouseIsDown) {
|
gyorgy@0
|
41 media.setCurrentTime(newTime);
|
gyorgy@0
|
42 }
|
gyorgy@0
|
43
|
gyorgy@0
|
44 // position floating time box
|
gyorgy@0
|
45 var pos = x - offset.left;
|
gyorgy@0
|
46 timefloat.css('left', pos);
|
gyorgy@0
|
47 timefloatcurrent.html( mejs.Utility.secondsToTimeCode(newTime) );
|
gyorgy@0
|
48 }
|
gyorgy@0
|
49 },
|
gyorgy@0
|
50 mouseIsDown = false,
|
gyorgy@0
|
51 mouseIsOver = false;
|
gyorgy@0
|
52
|
gyorgy@0
|
53 // handle clicks
|
gyorgy@0
|
54 //controls.find('.mejs-time-rail').delegate('span', 'click', handleMouseMove);
|
gyorgy@0
|
55 total
|
gyorgy@0
|
56 .bind('mousedown', function (e) {
|
gyorgy@0
|
57 mouseIsDown = true;
|
gyorgy@0
|
58 handleMouseMove(e);
|
gyorgy@0
|
59 return false;
|
gyorgy@0
|
60 });
|
gyorgy@0
|
61
|
gyorgy@0
|
62 controls.find('.mejs-time-rail')
|
gyorgy@0
|
63 .bind('mouseenter', function(e) {
|
gyorgy@0
|
64 mouseIsOver = true;
|
gyorgy@0
|
65 })
|
gyorgy@0
|
66 .bind('mouseleave',function(e) {
|
gyorgy@0
|
67 mouseIsOver = false;
|
gyorgy@0
|
68 });
|
gyorgy@0
|
69
|
gyorgy@0
|
70 $(document)
|
gyorgy@0
|
71 .bind('mouseup', function (e) {
|
gyorgy@0
|
72 mouseIsDown = false;
|
gyorgy@0
|
73 //handleMouseMove(e);
|
gyorgy@0
|
74 })
|
gyorgy@0
|
75 .bind('mousemove', function (e) {
|
gyorgy@0
|
76 if (mouseIsDown || mouseIsOver) {
|
gyorgy@0
|
77 handleMouseMove(e);
|
gyorgy@0
|
78 }
|
gyorgy@0
|
79 });
|
gyorgy@0
|
80
|
gyorgy@0
|
81 // loading
|
gyorgy@0
|
82 media.addEventListener('progress', function (e) {
|
gyorgy@0
|
83 player.setProgressRail(e);
|
gyorgy@0
|
84 player.setCurrentRail(e);
|
gyorgy@0
|
85 }, false);
|
gyorgy@0
|
86
|
gyorgy@0
|
87 // current time
|
gyorgy@0
|
88 media.addEventListener('timeupdate', function(e) {
|
gyorgy@0
|
89 player.setProgressRail(e);
|
gyorgy@0
|
90 player.setCurrentRail(e);
|
gyorgy@0
|
91 }, false);
|
gyorgy@0
|
92
|
gyorgy@0
|
93
|
gyorgy@0
|
94 // store for later use
|
gyorgy@0
|
95 t.loaded = loaded;
|
gyorgy@0
|
96 t.total = total;
|
gyorgy@0
|
97 t.current = current;
|
gyorgy@0
|
98 t.handle = handle;
|
gyorgy@0
|
99 }
|
gyorgy@0
|
100 MediaElementPlayer.prototype.setProgressRail = function(e) {
|
gyorgy@0
|
101
|
gyorgy@0
|
102 var
|
gyorgy@0
|
103 t = this,
|
gyorgy@0
|
104 target = (e != undefined) ? e.target : t.media,
|
gyorgy@0
|
105 percent = null;
|
gyorgy@0
|
106
|
gyorgy@0
|
107 // newest HTML5 spec has buffered array (FF4, Webkit)
|
gyorgy@0
|
108 if (target && target.buffered && target.buffered.length > 0 && target.buffered.end && target.duration) {
|
gyorgy@0
|
109 // TODO: account for a real array with multiple values (only Firefox 4 has this so far)
|
gyorgy@0
|
110 percent = target.buffered.end(0) / target.duration;
|
gyorgy@0
|
111 }
|
gyorgy@0
|
112 // Some browsers (e.g., FF3.6 and Safari 5) cannot calculate target.bufferered.end()
|
gyorgy@0
|
113 // to be anything other than 0. If the byte count is available we use this instead.
|
gyorgy@0
|
114 // Browsers that support the else if do not seem to have the bufferedBytes value and
|
gyorgy@0
|
115 // should skip to there. Tested in Safari 5, Webkit head, FF3.6, Chrome 6, IE 7/8.
|
gyorgy@0
|
116 else if (target && target.bytesTotal != undefined && target.bytesTotal > 0 && target.bufferedBytes != undefined) {
|
gyorgy@0
|
117 percent = target.bufferedBytes / target.bytesTotal;
|
gyorgy@0
|
118 }
|
gyorgy@0
|
119 // Firefox 3 with an Ogg file seems to go this way
|
gyorgy@0
|
120 else if (e && e.lengthComputable && e.total != 0) {
|
gyorgy@0
|
121 percent = e.loaded/e.total;
|
gyorgy@0
|
122 }
|
gyorgy@0
|
123
|
gyorgy@0
|
124 // finally update the progress bar
|
gyorgy@0
|
125 if (percent !== null) {
|
gyorgy@0
|
126 percent = Math.min(1, Math.max(0, percent));
|
gyorgy@0
|
127 // update loaded bar
|
gyorgy@0
|
128 if (t.loaded && t.total) {
|
gyorgy@0
|
129 t.loaded.width(t.total.width() * percent);
|
gyorgy@0
|
130 }
|
gyorgy@0
|
131 }
|
gyorgy@0
|
132 }
|
gyorgy@0
|
133 MediaElementPlayer.prototype.setCurrentRail = function() {
|
gyorgy@0
|
134
|
gyorgy@0
|
135 var t = this;
|
gyorgy@0
|
136
|
gyorgy@0
|
137 if (t.media.currentTime != undefined && t.media.duration) {
|
gyorgy@0
|
138
|
gyorgy@0
|
139 // update bar and handle
|
gyorgy@0
|
140 if (t.total && t.handle) {
|
gyorgy@0
|
141 var
|
gyorgy@0
|
142 newWidth = t.total.width() * t.media.currentTime / t.media.duration,
|
gyorgy@0
|
143 handlePos = newWidth - (t.handle.outerWidth(true) / 2);
|
gyorgy@0
|
144
|
gyorgy@0
|
145 t.current.width(newWidth);
|
gyorgy@0
|
146 t.handle.css('left', handlePos);
|
gyorgy@0
|
147 }
|
gyorgy@0
|
148 }
|
gyorgy@0
|
149
|
gyorgy@0
|
150 }
|
gyorgy@0
|
151
|
gyorgy@0
|
152 })(mejs.$); |