| author | hamidouk |
| Wed, 14 Dec 2011 12:09:45 +0100 | |
| branch | popcorn-port |
| changeset 458 | 5bafddd9e3ba |
| parent 448 | fa9400275846 |
| child 463 | 7ef123b2410f |
| 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() { |
44 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
|
| 458 | 45 |
IriSP.PopcornReplacement.media.muted = jwplayer(IriSP.PopcornReplacement._container).getMute(); |
| 388 | 46 |
}; |
47 |
||
| 431 | 48 |
IriSP.PopcornReplacement.jwplayer = function(container, options) { |
49 |
IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#' |
|
| 388 | 50 |
options.events = { |
| 431 | 51 |
onReady: IriSP.PopcornReplacement.__initApi, |
52 |
onTime: IriSP.PopcornReplacement.__timeHandler, |
|
| 442 | 53 |
onPlay: IriSP.PopcornReplacement.__playHandler, |
54 |
onPause: IriSP.PopcornReplacement.__pauseHandler, |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
55 |
onSeek: IriSP.PopcornReplacement.__seekHandler |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
56 |
} |
| 388 | 57 |
|
| 431 | 58 |
jwplayer(IriSP.PopcornReplacement._container).setup(options); |
59 |
IriSP.PopcornReplacement.media.duration = options.duration; |
|
60 |
return IriSP.PopcornReplacement; |
|
| 388 | 61 |
}; |
62 |
||
| 431 | 63 |
IriSP.PopcornReplacement.currentTime = function(time) { |
| 388 | 64 |
if (typeof(time) === "undefined") { |
| 431 | 65 |
return jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
| 388 | 66 |
} else { |
67 |
var currentTime = +time; |
|
| 431 | 68 |
jwplayer( IriSP.PopcornReplacement._container ).seek( currentTime ); |
69 |
return jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
|
| 388 | 70 |
} |
71 |
}; |
|
72 |
||
| 431 | 73 |
IriSP.PopcornReplacement.play = function() { |
74 |
IriSP.PopcornReplacement.media.paused = false; |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
75 |
IriSP.PopcornReplacement.trigger("play"); |
| 431 | 76 |
// IriSP.PopcornReplacement.trigger("playing"); |
77 |
jwplayer( IriSP.PopcornReplacement._container ).play(); |
|
| 388 | 78 |
}; |
79 |
|
|
| 431 | 80 |
IriSP.PopcornReplacement.pause = function() { |
81 |
if ( !IriSP.PopcornReplacement.media.paused ) { |
|
82 |
IriSP.PopcornReplacement.media.paused = true; |
|
83 |
IriSP.PopcornReplacement.trigger( "pause" ); |
|
84 |
jwplayer( IriSP.PopcornReplacement._container ).pause(); |
|
| 388 | 85 |
} |
86 |
}; |
|
87 |
||
| 431 | 88 |
IriSP.PopcornReplacement.muted = function(val) { |
| 388 | 89 |
if (typeof(val) !== "undefined") { |
| 390 | 90 |
|
| 431 | 91 |
if (jwplayer(IriSP.PopcornReplacement._container).getMute() !== val) { |
| 390 | 92 |
if (val) { |
| 431 | 93 |
jwplayer(IriSP.PopcornReplacement._container).setMute(true); |
| 448 | 94 |
IriSP.PopcornReplacement.media.muted = true; |
| 388 | 95 |
} else { |
| 431 | 96 |
jwplayer( IriSP.PopcornReplacement._container ).setMute(false); |
| 448 | 97 |
IriSP.PopcornReplacement.media.muted = false; |
| 388 | 98 |
} |
99 |
||
| 431 | 100 |
IriSP.PopcornReplacement.trigger( "volumechange" ); |
| 388 | 101 |
} |
102 |
|
|
| 431 | 103 |
return jwplayer( IriSP.PopcornReplacement._container ).getMute(); |
| 388 | 104 |
} else { |
| 431 | 105 |
return jwplayer( IriSP.PopcornReplacement._container ).getMute(); |
| 388 | 106 |
} |
| 390 | 107 |
}; |
108 |
||
| 431 | 109 |
IriSP.PopcornReplacement.mute = IriSP.PopcornReplacement.muted; |
| 394 | 110 |
|
| 431 | 111 |
IriSP.PopcornReplacement.__codes = []; |
112 |
IriSP.PopcornReplacement.code = function(options) { |
|
113 |
IriSP.PopcornReplacement.__codes.push(options); |
|
114 |
return IriSP.PopcornReplacement; |
|
| 390 | 115 |
}; |
116 |
||
| 431 | 117 |
IriSP.PopcornReplacement.__runCode = function() { |
118 |
var currentTime = jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
|
| 390 | 119 |
var i = 0; |
| 431 | 120 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
121 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
| 391 | 122 |
if (currentTime == c.start) { |
| 390 | 123 |
c.onStart(); |
124 |
} |
|
125 |
|
|
| 391 | 126 |
if (currentTime == c.end) { |
| 390 | 127 |
c.onEnd(); |
128 |
} |
|
| 388 | 129 |
|
| 390 | 130 |
} |
| 394 | 131 |
}; |
| 391 | 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; |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
139 |
|
|
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]; |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
143 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
144 |
if (pos >= c.start && pos < c.end && |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
145 |
pos - 0.1 <= c.start) { |
|
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 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
149 |
if (pos >= c.start && pos >= c.end && |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
150 |
pos - 0.1 <= c.end) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
151 |
c.onEnd(); |
|
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 |
|
| 431 | 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; |
| 431 | 161 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
162 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
163 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
164 |
if (event.position >= c.start && event.position < c.end) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
165 |
c.onEnd(); |
|
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 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
168 |
if (typeof(event.offset) === "undefined") |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
169 |
event.offset = 0; |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
170 |
if (event.offset >= c.start && event.offset < c.end) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
171 |
c.onStart(); |
|
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 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
175 |
|
| 431 | 176 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
177 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
178 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
179 |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
180 |
IriSP.PopcornReplacement.__playHandler = function(event) { |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
181 |
IriSP.PopcornReplacement.media.paused = false; |
| 442 | 182 |
IriSP.PopcornReplacement.trigger("play"); |
|
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 |
|
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
185 |
IriSP.PopcornReplacement.__pauseHandler = function(event) { |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
186 |
IriSP.PopcornReplacement.media.paused = true; |
| 442 | 187 |
IriSP.PopcornReplacement.trigger("pause"); |
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
188 |
}; |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
189 |
|
| 431 | 190 |
IriSP.PopcornReplacement.roundTime = function() { |
191 |
var currentTime = IriSP.PopcornReplacement.currentTime(); |
|
| 394 | 192 |
return Math.round(currentTime); |
193 |
}; |