| author | veltr |
| Wed, 11 Apr 2012 17:06:11 +0200 | |
| changeset 857 | fa614dc66b0b |
| parent 841 | 8da49ff273e0 |
| child 870 | 2c025db10a10 |
| permissions | -rw-r--r-- |
| 387 | 1 |
/* wrapper that simulates popcorn.js because |
2 |
popcorn is a bit unstable at the time */ |
|
| 388 | 3 |
|
| 702 | 4 |
IriSP.PopcornReplacement = { |
| 442 | 5 |
}; |
| 390 | 6 |
|
| 702 | 7 |
/** base class for our popcorn-compatible players. |
| 699 | 8 |
*/ |
| 702 | 9 |
IriSP.PopcornReplacement.player = function(container, options) { |
10 |
/* the jwplayer calls the callbacks in the global space so we need to |
|
11 |
preserve them using IriSP.wrap */ |
|
12 |
this.callbacks = { |
|
13 |
onReady: IriSP.wrap(this, this.__initApi), |
|
14 |
onTime: IriSP.wrap(this, this.__timeHandler), |
|
15 |
onPlay: IriSP.wrap(this, this.__playHandler), |
|
16 |
onPause: IriSP.wrap(this, this.__pauseHandler), |
|
17 |
onSeek: IriSP.wrap(this, this.__seekHandler) |
|
18 |
}; |
|
19 |
|
|
| 699 | 20 |
this.media = { |
21 |
"paused": true, |
|
22 |
"muted": false |
|
23 |
}; |
|
| 702 | 24 |
|
25 |
this.container = container.slice(1); //eschew the '#' |
|
| 699 | 26 |
|
27 |
this.msgPump = {}; /* dictionnary used to receive and send messages */ |
|
| 702 | 28 |
this.__codes = []; /* used to schedule the execution of a piece of code in |
29 |
a segment (similar to the popcorn.code plugin). */ |
|
| 785 | 30 |
|
31 |
this._options = options; |
|
| 702 | 32 |
|
| 388 | 33 |
}; |
34 |
||
| 699 | 35 |
IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) { |
36 |
if (!this.msgPump.hasOwnProperty(msg)) |
|
37 |
this.msgPump[msg] = []; |
|
38 |
||
39 |
this.msgPump[msg].push(callback); |
|
40 |
}; |
|
41 |
||
42 |
IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) { |
|
43 |
if (!this.msgPump.hasOwnProperty(msg)) |
|
|
445
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
44 |
return; |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
45 |
|
| 699 | 46 |
var d = this.msgPump[msg]; |
| 596 | 47 |
|
| 586 | 48 |
for(var i = 0; i < d.length; i++) { |
49 |
d[i].call(window, params); |
|
|
445
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
50 |
} |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
51 |
|
| 388 | 52 |
}; |
53 |
||
| 702 | 54 |
IriSP.PopcornReplacement.player.prototype.guid = function(prefix) { |
| 388 | 55 |
var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
56 |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
|
57 |
return v.toString(16); |
|
58 |
}); |
|
59 |
||
60 |
return prefix + str; |
|
61 |
}; |
|
62 |
||
| 702 | 63 |
/** init the api after that flash player has been setup - called by the callback |
64 |
defined by the embedded flash player |
|
65 |
*/ |
|
66 |
IriSP.PopcornReplacement.player.prototype.__initApi = function() { |
|
67 |
this.trigger("loadedmetadata"); // we've done more than loading metadata of course, |
|
|
463
7ef123b2410f
trigger a bunch of signals for popcorn compatibility.
hamidouk
parents:
458
diff
changeset
|
68 |
// but popcorn doesn't need to know more. |
| 702 | 69 |
this.media.muted = this.playerFns.getMute(); |
| 578 | 70 |
/* some programmed segments are supposed to be run at the beginning */ |
71 |
var i = 0; |
|
| 702 | 72 |
for(i = 0; i < this.__codes.length; i++) { |
73 |
var c = this.__codes[i]; |
|
| 578 | 74 |
if (0 == c.start) { |
75 |
c.onStart(); |
|
76 |
} |
|
77 |
|
|
78 |
if (0 == c.end) { |
|
79 |
c.onEnd(); |
|
80 |
} |
|
81 |
} |
|
| 388 | 82 |
}; |
83 |
||
| 702 | 84 |
/* |
| 431 | 85 |
IriSP.PopcornReplacement.jwplayer = function(container, options) { |
86 |
IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#' |
|
| 388 | 87 |
options.events = { |
| 431 | 88 |
onReady: IriSP.PopcornReplacement.__initApi, |
89 |
onTime: IriSP.PopcornReplacement.__timeHandler, |
|
| 442 | 90 |
onPlay: IriSP.PopcornReplacement.__playHandler, |
91 |
onPause: IriSP.PopcornReplacement.__pauseHandler, |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
92 |
onSeek: IriSP.PopcornReplacement.__seekHandler |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
93 |
} |
| 388 | 94 |
|
| 431 | 95 |
jwplayer(IriSP.PopcornReplacement._container).setup(options); |
96 |
IriSP.PopcornReplacement.media.duration = options.duration; |
|
97 |
return IriSP.PopcornReplacement; |
|
| 388 | 98 |
}; |
| 702 | 99 |
*/ |
| 388 | 100 |
|
| 702 | 101 |
IriSP.PopcornReplacement.player.prototype.currentTime = function(time) { |
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
604
diff
changeset
|
102 |
if (typeof(time) === "undefined") { |
| 702 | 103 |
return this.playerFns.getPosition(); |
| 388 | 104 |
} else { |
105 |
var currentTime = +time; |
|
| 723 | 106 |
this.playerFns.seek(currentTime); |
| 604 | 107 |
return currentTime; |
| 388 | 108 |
} |
109 |
}; |
|
110 |
||
| 702 | 111 |
IriSP.PopcornReplacement.player.prototype.play = function() { |
112 |
this.media.paused = false; |
|
113 |
this.trigger("play"); |
|
114 |
//IriSP.PopcornReplacement.trigger("playing"); |
|
115 |
this.playerFns.play(); |
|
| 388 | 116 |
}; |
117 |
|
|
| 702 | 118 |
IriSP.PopcornReplacement.player.prototype.pause = function() { |
| 841 | 119 |
// if ( !this.media.paused ) { |
| 702 | 120 |
this.media.paused = true; |
121 |
this.trigger( "pause" ); |
|
122 |
this.playerFns.pause(); |
|
| 841 | 123 |
// } |
| 390 | 124 |
}; |
125 |
||
| 702 | 126 |
IriSP.PopcornReplacement.player.prototype.muted = function(val) { |
127 |
if (typeof(val) !== "undefined") { |
|
128 |
||
129 |
if (this.playerFns.getMute() !== val) { |
|
130 |
if (val) { |
|
131 |
this.playerFns.setMute(true); |
|
132 |
this.media.muted = true; |
|
133 |
} else { |
|
134 |
this.playerFns.setMute(false); |
|
135 |
this.media.muted = false; |
|
136 |
} |
|
| 394 | 137 |
|
| 702 | 138 |
this.trigger( "volumechange" ); |
139 |
} |
|
140 |
|
|
141 |
return this.playerFns.getMute(); |
|
142 |
} else { |
|
143 |
return this.playerFns.getMute(); |
|
144 |
} |
|
145 |
}; |
|
146 |
||
| 839 | 147 |
IriSP.PopcornReplacement.player.prototype.volume = function(val) { |
148 |
if (typeof this.playerFns.getVolume == "undefined" || typeof this.playerFns.setVolume == "undefined") { |
|
149 |
return false; |
|
150 |
} |
|
151 |
var _vol = this.playerFns.getVolume(); |
|
152 |
if (typeof(val) !== "undefined" && parseFloat(val) !== NaN) { |
|
153 |
val = Math.max(0, Math.min(1, val)); |
|
154 |
if (parseFloat(val) != parseFloat(_vol)) { |
|
155 |
this.playerFns.setVolume(val); |
|
156 |
this.trigger("volumechange"); |
|
157 |
_vol = this.playerFns.getVolume(); |
|
158 |
} |
|
159 |
} |
|
160 |
return _vol; |
|
161 |
}; |
|
162 |
||
| 702 | 163 |
IriSP.PopcornReplacement.player.prototype.mute = IriSP.PopcornReplacement.player.prototype.muted; |
164 |
||
165 |
IriSP.PopcornReplacement.player.prototype.code = function(options) { |
|
166 |
this.__codes.push(options); |
|
167 |
return this; |
|
| 390 | 168 |
}; |
169 |
||
| 394 | 170 |
/* called everytime the player updates itself |
171 |
(onTime event) |
|
172 |
*/ |
|
173 |
||
| 706 | 174 |
IriSP.PopcornReplacement.player.prototype.__timeHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
175 |
var pos = event.position; |
| 702 | 176 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
177 |
var i = 0; |
| 702 | 178 |
for(i = 0; i < this.__codes.length; i++) { |
179 |
var c = this.__codes[i]; |
|
| 580 | 180 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
181 |
if (pos >= c.start && pos < c.end && |
| 580 | 182 |
pos - 1 <= c.start) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
183 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
184 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
185 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
186 |
if (pos > c.start && pos > c.end && |
| 580 | 187 |
pos - 1 <= c.end) { |
| 578 | 188 |
c.onEnd(); |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
189 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
190 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
191 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
192 |
|
| 702 | 193 |
this.trigger("timeupdate"); |
| 390 | 194 |
}; |
| 394 | 195 |
|
| 702 | 196 |
IriSP.PopcornReplacement.player.prototype.__seekHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
197 |
var i = 0; |
| 723 | 198 |
|
| 702 | 199 |
for(i = 0; i < this.__codes.length; i++) { |
200 |
var c = this.__codes[i]; |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
201 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
202 |
if (event.position >= c.start && event.position < c.end) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
203 |
c.onEnd(); |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
204 |
} |
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
205 |
} |
| 580 | 206 |
|
| 702 | 207 |
for(i = 0; i < this.__codes.length; i++) { |
208 |
var c = this.__codes[i]; |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
209 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
210 |
if (typeof(event.offset) === "undefined") |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
211 |
event.offset = 0; |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
212 |
|
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
213 |
if (event.offset >= c.start && event.offset < c.end) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
214 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
215 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
216 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
217 |
} |
| 723 | 218 |
|
| 750 | 219 |
/* this signal sends as an extra argument the position in the video. |
220 |
As far as I know, this argument is not provided by popcorn */ |
|
| 749 | 221 |
this.trigger("seeked", event.offset); |
| 702 | 222 |
}; |
223 |
||
224 |
IriSP.PopcornReplacement.player.prototype.__playHandler = function(event) { |
|
225 |
this.media.paused = false; |
|
226 |
this.trigger("play"); |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
227 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
228 |
|
| 702 | 229 |
IriSP.PopcornReplacement.player.prototype.__pauseHandler = function(event) { |
230 |
this.media.paused = true; |
|
231 |
this.trigger("pause"); |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
232 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
233 |
|
| 702 | 234 |
IriSP.PopcornReplacement.player.prototype.roundTime = function() { |
235 |
var currentTime = this.currentTime(); |
|
| 394 | 236 |
return Math.round(currentTime); |
|
711
323205a7bd39
separated jwplayer code from pop.js and put it into its own folder, players/.
hamidouk
parents:
706
diff
changeset
|
237 |
}; |