| author | hamidouk |
| Thu, 26 Jan 2012 13:01:57 +0100 | |
| branch | popcorn-port |
| changeset 720 | 08b8b3ce30e4 |
| parent 711 | 323205a7bd39 |
| child 723 | bbf9914a5f99 |
| 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). */ |
|
30 |
|
|
| 388 | 31 |
}; |
32 |
||
| 699 | 33 |
IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) { |
34 |
if (!this.msgPump.hasOwnProperty(msg)) |
|
35 |
this.msgPump[msg] = []; |
|
36 |
||
37 |
this.msgPump[msg].push(callback); |
|
38 |
}; |
|
39 |
||
40 |
IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) { |
|
41 |
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
|
42 |
return; |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
43 |
|
| 699 | 44 |
var d = this.msgPump[msg]; |
| 596 | 45 |
|
| 586 | 46 |
for(var i = 0; i < d.length; i++) { |
47 |
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
|
48 |
} |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
49 |
|
| 388 | 50 |
}; |
51 |
||
| 702 | 52 |
IriSP.PopcornReplacement.player.prototype.guid = function(prefix) { |
| 388 | 53 |
var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
54 |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
|
55 |
return v.toString(16); |
|
56 |
}); |
|
57 |
||
58 |
return prefix + str; |
|
59 |
}; |
|
60 |
||
| 702 | 61 |
/** init the api after that flash player has been setup - called by the callback |
62 |
defined by the embedded flash player |
|
63 |
*/ |
|
64 |
IriSP.PopcornReplacement.player.prototype.__initApi = function() { |
|
65 |
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
|
66 |
// but popcorn doesn't need to know more. |
| 702 | 67 |
this.media.muted = this.playerFns.getMute(); |
| 578 | 68 |
/* some programmed segments are supposed to be run at the beginning */ |
69 |
var i = 0; |
|
| 702 | 70 |
for(i = 0; i < this.__codes.length; i++) { |
71 |
var c = this.__codes[i]; |
|
| 578 | 72 |
if (0 == c.start) { |
73 |
c.onStart(); |
|
74 |
} |
|
75 |
|
|
76 |
if (0 == c.end) { |
|
77 |
c.onEnd(); |
|
78 |
} |
|
79 |
} |
|
| 388 | 80 |
}; |
81 |
||
| 702 | 82 |
/* |
| 431 | 83 |
IriSP.PopcornReplacement.jwplayer = function(container, options) { |
84 |
IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#' |
|
| 388 | 85 |
options.events = { |
| 431 | 86 |
onReady: IriSP.PopcornReplacement.__initApi, |
87 |
onTime: IriSP.PopcornReplacement.__timeHandler, |
|
| 442 | 88 |
onPlay: IriSP.PopcornReplacement.__playHandler, |
89 |
onPause: IriSP.PopcornReplacement.__pauseHandler, |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
90 |
onSeek: IriSP.PopcornReplacement.__seekHandler |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
91 |
} |
| 388 | 92 |
|
| 431 | 93 |
jwplayer(IriSP.PopcornReplacement._container).setup(options); |
94 |
IriSP.PopcornReplacement.media.duration = options.duration; |
|
95 |
return IriSP.PopcornReplacement; |
|
| 388 | 96 |
}; |
| 702 | 97 |
*/ |
| 388 | 98 |
|
| 702 | 99 |
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
|
100 |
if (typeof(time) === "undefined") { |
| 702 | 101 |
return this.playerFns.getPosition(); |
| 388 | 102 |
} else { |
103 |
var currentTime = +time; |
|
| 702 | 104 |
this.playerFns.seek( currentTime ); |
105 |
this.__delay_seek_signal = true; /* FIXME : useless ? */ |
|
106 |
this.trigger("seeked"); |
|
| 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() { |
119 |
if ( !this.media.paused ) { |
|
120 |
this.media.paused = true; |
|
121 |
this.trigger( "pause" ); |
|
122 |
this.playerFns.pause(); |
|
| 388 | 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 |
||
147 |
IriSP.PopcornReplacement.player.prototype.mute = IriSP.PopcornReplacement.player.prototype.muted; |
|
148 |
||
149 |
IriSP.PopcornReplacement.player.prototype.code = function(options) { |
|
150 |
this.__codes.push(options); |
|
151 |
return this; |
|
| 390 | 152 |
}; |
153 |
||
| 394 | 154 |
/* called everytime the player updates itself |
155 |
(onTime event) |
|
156 |
*/ |
|
157 |
||
| 706 | 158 |
IriSP.PopcornReplacement.player.prototype.__timeHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
159 |
var pos = event.position; |
| 702 | 160 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
161 |
var i = 0; |
| 702 | 162 |
for(i = 0; i < this.__codes.length; i++) { |
163 |
var c = this.__codes[i]; |
|
| 580 | 164 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
165 |
if (pos >= c.start && pos < c.end && |
| 580 | 166 |
pos - 1 <= c.start) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
167 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
168 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
169 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
170 |
if (pos > c.start && pos > c.end && |
| 580 | 171 |
pos - 1 <= c.end) { |
| 578 | 172 |
c.onEnd(); |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
173 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
174 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
175 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
176 |
|
| 702 | 177 |
this.trigger("timeupdate"); |
| 390 | 178 |
}; |
| 394 | 179 |
|
| 702 | 180 |
IriSP.PopcornReplacement.player.prototype.__seekHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
181 |
var i = 0; |
| 706 | 182 |
|
| 702 | 183 |
for(i = 0; i < this.__codes.length; i++) { |
184 |
var c = this.__codes[i]; |
|
|
417
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 (event.position >= c.start && event.position < c.end) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
187 |
c.onEnd(); |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
188 |
} |
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
189 |
} |
| 580 | 190 |
|
| 702 | 191 |
for(i = 0; i < this.__codes.length; i++) { |
192 |
var c = this.__codes[i]; |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
193 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
194 |
if (typeof(event.offset) === "undefined") |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
195 |
event.offset = 0; |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
196 |
|
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
197 |
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
|
198 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
199 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
200 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
201 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
202 |
|
| 702 | 203 |
this.trigger("timeupdate"); |
204 |
}; |
|
205 |
||
206 |
IriSP.PopcornReplacement.player.prototype.__playHandler = function(event) { |
|
207 |
this.media.paused = false; |
|
208 |
this.trigger("play"); |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
209 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
210 |
|
| 702 | 211 |
IriSP.PopcornReplacement.player.prototype.__pauseHandler = function(event) { |
212 |
this.media.paused = true; |
|
213 |
this.trigger("pause"); |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
214 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
215 |
|
| 702 | 216 |
IriSP.PopcornReplacement.player.prototype.roundTime = function() { |
217 |
var currentTime = this.currentTime(); |
|
| 394 | 218 |
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
|
219 |
}; |