| author | hamidouk |
| Tue, 31 Jan 2012 11:58:46 +0100 | |
| branch | popcorn-port |
| changeset 749 | e9ee52225395 |
| parent 723 | bbf9914a5f99 |
| child 750 | a1a3d09de1f4 |
| 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; |
|
| 723 | 104 |
this.playerFns.seek(currentTime); |
| 604 | 105 |
return currentTime; |
| 388 | 106 |
} |
107 |
}; |
|
108 |
||
| 702 | 109 |
IriSP.PopcornReplacement.player.prototype.play = function() { |
110 |
this.media.paused = false; |
|
111 |
this.trigger("play"); |
|
112 |
//IriSP.PopcornReplacement.trigger("playing"); |
|
113 |
this.playerFns.play(); |
|
| 388 | 114 |
}; |
115 |
|
|
| 702 | 116 |
IriSP.PopcornReplacement.player.prototype.pause = function() { |
117 |
if ( !this.media.paused ) { |
|
118 |
this.media.paused = true; |
|
119 |
this.trigger( "pause" ); |
|
120 |
this.playerFns.pause(); |
|
| 388 | 121 |
} |
| 390 | 122 |
}; |
123 |
||
| 702 | 124 |
IriSP.PopcornReplacement.player.prototype.muted = function(val) { |
125 |
if (typeof(val) !== "undefined") { |
|
126 |
||
127 |
if (this.playerFns.getMute() !== val) { |
|
128 |
if (val) { |
|
129 |
this.playerFns.setMute(true); |
|
130 |
this.media.muted = true; |
|
131 |
} else { |
|
132 |
this.playerFns.setMute(false); |
|
133 |
this.media.muted = false; |
|
134 |
} |
|
| 394 | 135 |
|
| 702 | 136 |
this.trigger( "volumechange" ); |
137 |
} |
|
138 |
|
|
139 |
return this.playerFns.getMute(); |
|
140 |
} else { |
|
141 |
return this.playerFns.getMute(); |
|
142 |
} |
|
143 |
}; |
|
144 |
||
145 |
IriSP.PopcornReplacement.player.prototype.mute = IriSP.PopcornReplacement.player.prototype.muted; |
|
146 |
||
147 |
IriSP.PopcornReplacement.player.prototype.code = function(options) { |
|
148 |
this.__codes.push(options); |
|
149 |
return this; |
|
| 390 | 150 |
}; |
151 |
||
| 394 | 152 |
/* called everytime the player updates itself |
153 |
(onTime event) |
|
154 |
*/ |
|
155 |
||
| 706 | 156 |
IriSP.PopcornReplacement.player.prototype.__timeHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
157 |
var pos = event.position; |
| 702 | 158 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
159 |
var i = 0; |
| 702 | 160 |
for(i = 0; i < this.__codes.length; i++) { |
161 |
var c = this.__codes[i]; |
|
| 580 | 162 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
163 |
if (pos >= c.start && pos < c.end && |
| 580 | 164 |
pos - 1 <= c.start) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
165 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
166 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
167 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
168 |
if (pos > c.start && pos > c.end && |
| 580 | 169 |
pos - 1 <= c.end) { |
| 578 | 170 |
c.onEnd(); |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
171 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
172 |
|
|
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 |
|
| 702 | 175 |
this.trigger("timeupdate"); |
| 390 | 176 |
}; |
| 394 | 177 |
|
| 702 | 178 |
IriSP.PopcornReplacement.player.prototype.__seekHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
179 |
var i = 0; |
| 723 | 180 |
|
| 702 | 181 |
for(i = 0; i < this.__codes.length; i++) { |
182 |
var c = this.__codes[i]; |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
183 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
184 |
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
|
185 |
c.onEnd(); |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
186 |
} |
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
187 |
} |
| 580 | 188 |
|
| 702 | 189 |
for(i = 0; i < this.__codes.length; i++) { |
190 |
var c = this.__codes[i]; |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
191 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
192 |
if (typeof(event.offset) === "undefined") |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
193 |
event.offset = 0; |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
194 |
|
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
195 |
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
|
196 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
197 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
198 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
199 |
} |
| 723 | 200 |
|
| 749 | 201 |
this.trigger("seeked", event.offset); |
| 702 | 202 |
}; |
203 |
||
204 |
IriSP.PopcornReplacement.player.prototype.__playHandler = function(event) { |
|
205 |
this.media.paused = false; |
|
206 |
this.trigger("play"); |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
207 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
208 |
|
| 702 | 209 |
IriSP.PopcornReplacement.player.prototype.__pauseHandler = function(event) { |
210 |
this.media.paused = true; |
|
211 |
this.trigger("pause"); |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
212 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
213 |
|
| 702 | 214 |
IriSP.PopcornReplacement.player.prototype.roundTime = function() { |
215 |
var currentTime = this.currentTime(); |
|
| 394 | 216 |
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
|
217 |
}; |