| author | hamidouk |
| Thu, 05 Jan 2012 14:57:37 +0100 | |
| branch | popcorn-port |
| changeset 586 | a3705fc7e054 |
| parent 580 | 47fb5cd44900 |
| child 596 | a0d2c5b96bee |
| permissions | -rw-r--r-- |
| 387 | 1 |
/* wrapper that simulates popcorn.js because |
2 |
popcorn is a bit unstable at the time */ |
|
| 388 | 3 |
|
|
445
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
4 |
IriSP.PopcornReplacement = { |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
5 |
msgPump : {} /* used by jquery to receive and send messages */ |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
6 |
}; |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
7 |
|
| 442 | 8 |
IriSP.PopcornReplacement.media = { |
| 448 | 9 |
"paused": true, |
10 |
"muted": false |
|
| 442 | 11 |
}; |
| 390 | 12 |
|
| 431 | 13 |
IriSP.PopcornReplacement.listen = function(msg, callback) { |
|
445
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
14 |
// IriSP.jQuery(IriSP.PopcornReplacement.msgPump).bind(msg, function(event, rest) { callback(rest); }); |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
15 |
if (!IriSP.PopcornReplacement.msgPump.hasOwnProperty(msg)) |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
16 |
IriSP.PopcornReplacement.msgPump[msg] = []; |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
17 |
|
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
18 |
IriSP.PopcornReplacement.msgPump[msg].push(callback); |
| 388 | 19 |
}; |
20 |
||
| 431 | 21 |
IriSP.PopcornReplacement.trigger = function(msg, params) { |
|
445
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
22 |
// IriSP.jQuery(IriSP.PopcornReplacement.msgPump).trigger(msg, params); |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
23 |
|
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
24 |
if (!IriSP.PopcornReplacement.msgPump.hasOwnProperty(msg)) |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
25 |
return; |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
26 |
|
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
27 |
var d = IriSP.PopcornReplacement.msgPump[msg]; |
| 586 | 28 |
var i = 0; |
29 |
for(var i = 0; i < d.length; i++) { |
|
30 |
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
|
31 |
} |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
32 |
|
| 388 | 33 |
}; |
34 |
||
| 431 | 35 |
IriSP.PopcornReplacement.guid = function(prefix) { |
| 388 | 36 |
var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
37 |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
|
38 |
return v.toString(16); |
|
39 |
}); |
|
40 |
||
41 |
return prefix + str; |
|
42 |
}; |
|
43 |
||
| 431 | 44 |
IriSP.PopcornReplacement.__initApi = function() { |
|
463
7ef123b2410f
trigger a bunch of signals for popcorn compatibility.
hamidouk
parents:
458
diff
changeset
|
45 |
IriSP.PopcornReplacement.trigger("loadedmetadata"); // we've done more than loading metadata of course, |
|
7ef123b2410f
trigger a bunch of signals for popcorn compatibility.
hamidouk
parents:
458
diff
changeset
|
46 |
// but popcorn doesn't need to know more. |
| 458 | 47 |
IriSP.PopcornReplacement.media.muted = jwplayer(IriSP.PopcornReplacement._container).getMute(); |
| 578 | 48 |
|
49 |
/* some programmed segments are supposed to be run at the beginning */ |
|
50 |
var i = 0; |
|
51 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
|
52 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
53 |
if (0 == c.start) { |
|
54 |
c.onStart(); |
|
55 |
} |
|
56 |
|
|
57 |
if (0 == c.end) { |
|
58 |
c.onEnd(); |
|
59 |
} |
|
60 |
} |
|
| 388 | 61 |
}; |
62 |
||
| 431 | 63 |
IriSP.PopcornReplacement.jwplayer = function(container, options) { |
64 |
IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#' |
|
| 388 | 65 |
options.events = { |
| 431 | 66 |
onReady: IriSP.PopcornReplacement.__initApi, |
67 |
onTime: IriSP.PopcornReplacement.__timeHandler, |
|
| 442 | 68 |
onPlay: IriSP.PopcornReplacement.__playHandler, |
69 |
onPause: IriSP.PopcornReplacement.__pauseHandler, |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
70 |
onSeek: IriSP.PopcornReplacement.__seekHandler |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
71 |
} |
| 388 | 72 |
|
| 431 | 73 |
jwplayer(IriSP.PopcornReplacement._container).setup(options); |
74 |
IriSP.PopcornReplacement.media.duration = options.duration; |
|
75 |
return IriSP.PopcornReplacement; |
|
| 388 | 76 |
}; |
77 |
||
| 431 | 78 |
IriSP.PopcornReplacement.currentTime = function(time) { |
| 388 | 79 |
if (typeof(time) === "undefined") { |
| 431 | 80 |
return jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
| 388 | 81 |
} else { |
82 |
var currentTime = +time; |
|
| 431 | 83 |
jwplayer( IriSP.PopcornReplacement._container ).seek( currentTime ); |
|
463
7ef123b2410f
trigger a bunch of signals for popcorn compatibility.
hamidouk
parents:
458
diff
changeset
|
84 |
IriSP.PopcornReplacement.trigger("seeked"); |
| 431 | 85 |
return jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
| 388 | 86 |
} |
87 |
}; |
|
88 |
||
| 431 | 89 |
IriSP.PopcornReplacement.play = function() { |
90 |
IriSP.PopcornReplacement.media.paused = false; |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
91 |
IriSP.PopcornReplacement.trigger("play"); |
| 431 | 92 |
// IriSP.PopcornReplacement.trigger("playing"); |
93 |
jwplayer( IriSP.PopcornReplacement._container ).play(); |
|
| 388 | 94 |
}; |
95 |
|
|
| 431 | 96 |
IriSP.PopcornReplacement.pause = function() { |
97 |
if ( !IriSP.PopcornReplacement.media.paused ) { |
|
98 |
IriSP.PopcornReplacement.media.paused = true; |
|
99 |
IriSP.PopcornReplacement.trigger( "pause" ); |
|
100 |
jwplayer( IriSP.PopcornReplacement._container ).pause(); |
|
| 388 | 101 |
} |
102 |
}; |
|
103 |
||
| 431 | 104 |
IriSP.PopcornReplacement.muted = function(val) { |
| 388 | 105 |
if (typeof(val) !== "undefined") { |
| 390 | 106 |
|
| 431 | 107 |
if (jwplayer(IriSP.PopcornReplacement._container).getMute() !== val) { |
| 390 | 108 |
if (val) { |
| 431 | 109 |
jwplayer(IriSP.PopcornReplacement._container).setMute(true); |
| 448 | 110 |
IriSP.PopcornReplacement.media.muted = true; |
| 388 | 111 |
} else { |
| 431 | 112 |
jwplayer( IriSP.PopcornReplacement._container ).setMute(false); |
| 448 | 113 |
IriSP.PopcornReplacement.media.muted = false; |
| 388 | 114 |
} |
115 |
||
| 431 | 116 |
IriSP.PopcornReplacement.trigger( "volumechange" ); |
| 388 | 117 |
} |
118 |
|
|
| 431 | 119 |
return jwplayer( IriSP.PopcornReplacement._container ).getMute(); |
| 388 | 120 |
} else { |
| 431 | 121 |
return jwplayer( IriSP.PopcornReplacement._container ).getMute(); |
| 388 | 122 |
} |
| 390 | 123 |
}; |
124 |
||
| 431 | 125 |
IriSP.PopcornReplacement.mute = IriSP.PopcornReplacement.muted; |
| 394 | 126 |
|
| 431 | 127 |
IriSP.PopcornReplacement.__codes = []; |
128 |
IriSP.PopcornReplacement.code = function(options) { |
|
129 |
IriSP.PopcornReplacement.__codes.push(options); |
|
130 |
return IriSP.PopcornReplacement; |
|
| 390 | 131 |
}; |
132 |
||
| 394 | 133 |
/* called everytime the player updates itself |
134 |
(onTime event) |
|
135 |
*/ |
|
136 |
||
| 431 | 137 |
IriSP.PopcornReplacement.__timeHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
138 |
var pos = event.position; |
| 578 | 139 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
140 |
var i = 0; |
| 431 | 141 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
142 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
| 580 | 143 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
144 |
if (pos >= c.start && pos < c.end && |
| 580 | 145 |
pos - 1 <= c.start) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
146 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
147 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
148 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
149 |
if (pos > c.start && pos > c.end && |
| 580 | 150 |
pos - 1 <= c.end) { |
| 578 | 151 |
c.onEnd(); |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
152 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
153 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
154 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
155 |
|
| 431 | 156 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
| 390 | 157 |
}; |
| 394 | 158 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
159 |
IriSP.PopcornReplacement.__seekHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
160 |
var i = 0; |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
161 |
|
| 431 | 162 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
163 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
164 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
165 |
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
|
166 |
c.onEnd(); |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
167 |
} |
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
168 |
} |
| 580 | 169 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
170 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
171 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
172 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
173 |
if (typeof(event.offset) === "undefined") |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
174 |
event.offset = 0; |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
175 |
|
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
176 |
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
|
177 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
178 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
179 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
180 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
181 |
|
| 431 | 182 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
183 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
184 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
185 |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
186 |
IriSP.PopcornReplacement.__playHandler = function(event) { |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
187 |
IriSP.PopcornReplacement.media.paused = false; |
| 442 | 188 |
IriSP.PopcornReplacement.trigger("play"); |
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
189 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
190 |
|
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
191 |
IriSP.PopcornReplacement.__pauseHandler = function(event) { |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
192 |
IriSP.PopcornReplacement.media.paused = true; |
| 442 | 193 |
IriSP.PopcornReplacement.trigger("pause"); |
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
194 |
}; |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
195 |
|
| 431 | 196 |
IriSP.PopcornReplacement.roundTime = function() { |
197 |
var currentTime = IriSP.PopcornReplacement.currentTime(); |
|
| 394 | 198 |
return Math.round(currentTime); |
199 |
}; |