| author | hamidouk |
| Fri, 23 Dec 2011 11:38:47 +0100 | |
| branch | jsdoc |
| changeset 520 | fe008e95a716 |
| parent 477 | 1e51d638e7ea |
| child 578 | 8dd6ebb7a79d |
| 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]; |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
28 |
for(var entry in d) { |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
29 |
d[entry].call(window, params); |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
30 |
} |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
31 |
|
| 388 | 32 |
}; |
33 |
||
| 431 | 34 |
IriSP.PopcornReplacement.guid = function(prefix) { |
| 388 | 35 |
var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
36 |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
|
37 |
return v.toString(16); |
|
38 |
}); |
|
39 |
||
40 |
return prefix + str; |
|
41 |
}; |
|
42 |
||
| 431 | 43 |
IriSP.PopcornReplacement.__initApi = function() { |
|
463
7ef123b2410f
trigger a bunch of signals for popcorn compatibility.
hamidouk
parents:
458
diff
changeset
|
44 |
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
|
45 |
// but popcorn doesn't need to know more. |
| 458 | 46 |
IriSP.PopcornReplacement.media.muted = jwplayer(IriSP.PopcornReplacement._container).getMute(); |
| 388 | 47 |
}; |
48 |
||
| 431 | 49 |
IriSP.PopcornReplacement.jwplayer = function(container, options) { |
50 |
IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#' |
|
| 388 | 51 |
options.events = { |
| 431 | 52 |
onReady: IriSP.PopcornReplacement.__initApi, |
53 |
onTime: IriSP.PopcornReplacement.__timeHandler, |
|
| 442 | 54 |
onPlay: IriSP.PopcornReplacement.__playHandler, |
55 |
onPause: IriSP.PopcornReplacement.__pauseHandler, |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
56 |
onSeek: IriSP.PopcornReplacement.__seekHandler |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
57 |
} |
| 388 | 58 |
|
| 431 | 59 |
jwplayer(IriSP.PopcornReplacement._container).setup(options); |
60 |
IriSP.PopcornReplacement.media.duration = options.duration; |
|
61 |
return IriSP.PopcornReplacement; |
|
| 388 | 62 |
}; |
63 |
||
| 431 | 64 |
IriSP.PopcornReplacement.currentTime = function(time) { |
| 388 | 65 |
if (typeof(time) === "undefined") { |
| 431 | 66 |
return jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
| 388 | 67 |
} else { |
68 |
var currentTime = +time; |
|
| 431 | 69 |
jwplayer( IriSP.PopcornReplacement._container ).seek( currentTime ); |
|
463
7ef123b2410f
trigger a bunch of signals for popcorn compatibility.
hamidouk
parents:
458
diff
changeset
|
70 |
IriSP.PopcornReplacement.trigger("seeked"); |
| 431 | 71 |
return jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
| 388 | 72 |
} |
73 |
}; |
|
74 |
||
| 431 | 75 |
IriSP.PopcornReplacement.play = function() { |
76 |
IriSP.PopcornReplacement.media.paused = false; |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
77 |
IriSP.PopcornReplacement.trigger("play"); |
| 431 | 78 |
// IriSP.PopcornReplacement.trigger("playing"); |
79 |
jwplayer( IriSP.PopcornReplacement._container ).play(); |
|
| 388 | 80 |
}; |
81 |
|
|
| 431 | 82 |
IriSP.PopcornReplacement.pause = function() { |
83 |
if ( !IriSP.PopcornReplacement.media.paused ) { |
|
84 |
IriSP.PopcornReplacement.media.paused = true; |
|
85 |
IriSP.PopcornReplacement.trigger( "pause" ); |
|
86 |
jwplayer( IriSP.PopcornReplacement._container ).pause(); |
|
| 388 | 87 |
} |
88 |
}; |
|
89 |
||
| 431 | 90 |
IriSP.PopcornReplacement.muted = function(val) { |
| 388 | 91 |
if (typeof(val) !== "undefined") { |
| 390 | 92 |
|
| 431 | 93 |
if (jwplayer(IriSP.PopcornReplacement._container).getMute() !== val) { |
| 390 | 94 |
if (val) { |
| 431 | 95 |
jwplayer(IriSP.PopcornReplacement._container).setMute(true); |
| 448 | 96 |
IriSP.PopcornReplacement.media.muted = true; |
| 388 | 97 |
} else { |
| 431 | 98 |
jwplayer( IriSP.PopcornReplacement._container ).setMute(false); |
| 448 | 99 |
IriSP.PopcornReplacement.media.muted = false; |
| 388 | 100 |
} |
101 |
||
| 431 | 102 |
IriSP.PopcornReplacement.trigger( "volumechange" ); |
| 388 | 103 |
} |
104 |
|
|
| 431 | 105 |
return jwplayer( IriSP.PopcornReplacement._container ).getMute(); |
| 388 | 106 |
} else { |
| 431 | 107 |
return jwplayer( IriSP.PopcornReplacement._container ).getMute(); |
| 388 | 108 |
} |
| 390 | 109 |
}; |
110 |
||
| 431 | 111 |
IriSP.PopcornReplacement.mute = IriSP.PopcornReplacement.muted; |
| 394 | 112 |
|
| 431 | 113 |
IriSP.PopcornReplacement.__codes = []; |
114 |
IriSP.PopcornReplacement.code = function(options) { |
|
115 |
IriSP.PopcornReplacement.__codes.push(options); |
|
116 |
return IriSP.PopcornReplacement; |
|
| 390 | 117 |
}; |
118 |
||
| 431 | 119 |
IriSP.PopcornReplacement.__runCode = function() { |
120 |
var currentTime = jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
|
| 390 | 121 |
var i = 0; |
| 431 | 122 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
123 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
| 391 | 124 |
if (currentTime == c.start) { |
| 390 | 125 |
c.onStart(); |
126 |
} |
|
127 |
|
|
| 391 | 128 |
if (currentTime == c.end) { |
| 390 | 129 |
c.onEnd(); |
130 |
} |
|
| 388 | 131 |
|
| 390 | 132 |
} |
| 394 | 133 |
}; |
| 391 | 134 |
|
| 394 | 135 |
/* called everytime the player updates itself |
136 |
(onTime event) |
|
137 |
*/ |
|
138 |
||
| 431 | 139 |
IriSP.PopcornReplacement.__timeHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
140 |
var pos = event.position; |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
141 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
142 |
var i = 0; |
| 431 | 143 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
144 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
145 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
146 |
if (pos >= c.start && pos < c.end && |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
147 |
pos - 0.1 <= c.start) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
148 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
149 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
150 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
151 |
if (pos > c.start && pos > c.end && |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
152 |
pos - 0.1 <= c.end) { |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
153 |
console.log("eonedn"); |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
154 |
c.onEnd(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
155 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
156 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
157 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
158 |
|
| 431 | 159 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
| 390 | 160 |
}; |
| 394 | 161 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
162 |
IriSP.PopcornReplacement.__seekHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
163 |
var i = 0; |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
164 |
|
| 431 | 165 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
166 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
|
417
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 (event.position >= c.start && event.position < c.end) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
169 |
c.onEnd(); |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
170 |
} |
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
171 |
} |
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
172 |
|
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
173 |
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
|
174 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
175 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
176 |
if (typeof(event.offset) === "undefined") |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
177 |
event.offset = 0; |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
178 |
|
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
179 |
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
|
180 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
181 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
182 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
183 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
184 |
|
| 431 | 185 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
186 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
187 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
188 |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
189 |
IriSP.PopcornReplacement.__playHandler = function(event) { |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
190 |
IriSP.PopcornReplacement.media.paused = false; |
| 442 | 191 |
IriSP.PopcornReplacement.trigger("play"); |
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
192 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
193 |
|
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
194 |
IriSP.PopcornReplacement.__pauseHandler = function(event) { |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
195 |
IriSP.PopcornReplacement.media.paused = true; |
| 442 | 196 |
IriSP.PopcornReplacement.trigger("pause"); |
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
197 |
}; |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
198 |
|
| 431 | 199 |
IriSP.PopcornReplacement.roundTime = function() { |
200 |
var currentTime = IriSP.PopcornReplacement.currentTime(); |
|
| 394 | 201 |
return Math.round(currentTime); |
202 |
}; |