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