| author | hamidouk |
| Fri, 09 Dec 2011 15:36:00 +0100 | |
| branch | popcorn-port |
| changeset 445 | c2eac11a9053 |
| parent 442 | ee6594f6d00d |
| child 448 | fa9400275846 |
| 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 = { |
9 |
"paused": true |
|
10 |
}; |
|
| 390 | 11 |
|
| 431 | 12 |
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
|
13 |
// 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
|
14 |
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
|
15 |
IriSP.PopcornReplacement.msgPump[msg] = []; |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
16 |
|
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
17 |
IriSP.PopcornReplacement.msgPump[msg].push(callback); |
| 388 | 18 |
}; |
19 |
||
| 431 | 20 |
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
|
21 |
// 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
|
22 |
|
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
23 |
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
|
24 |
return; |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
25 |
|
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
26 |
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
|
27 |
for(var entry in d) { |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
28 |
d[entry].call(window, params); |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
29 |
} |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
30 |
|
| 388 | 31 |
}; |
32 |
||
| 431 | 33 |
IriSP.PopcornReplacement.guid = function(prefix) { |
| 388 | 34 |
var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
35 |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
|
36 |
return v.toString(16); |
|
37 |
}); |
|
38 |
||
39 |
return prefix + str; |
|
40 |
}; |
|
41 |
||
| 431 | 42 |
IriSP.PopcornReplacement.__initApi = function() { |
43 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
|
| 388 | 44 |
}; |
45 |
||
| 431 | 46 |
IriSP.PopcornReplacement.jwplayer = function(container, options) { |
47 |
IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#' |
|
| 388 | 48 |
options.events = { |
| 431 | 49 |
onReady: IriSP.PopcornReplacement.__initApi, |
50 |
onTime: IriSP.PopcornReplacement.__timeHandler, |
|
| 442 | 51 |
onPlay: IriSP.PopcornReplacement.__playHandler, |
52 |
onPause: IriSP.PopcornReplacement.__pauseHandler, |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
53 |
onSeek: IriSP.PopcornReplacement.__seekHandler |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
54 |
} |
| 388 | 55 |
|
| 431 | 56 |
jwplayer(IriSP.PopcornReplacement._container).setup(options); |
57 |
IriSP.PopcornReplacement.media.duration = options.duration; |
|
58 |
return IriSP.PopcornReplacement; |
|
| 388 | 59 |
}; |
60 |
||
| 431 | 61 |
IriSP.PopcornReplacement.currentTime = function(time) { |
| 388 | 62 |
if (typeof(time) === "undefined") { |
| 431 | 63 |
return jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
| 388 | 64 |
} else { |
65 |
var currentTime = +time; |
|
| 431 | 66 |
jwplayer( IriSP.PopcornReplacement._container ).seek( currentTime ); |
67 |
return jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
|
| 388 | 68 |
} |
69 |
}; |
|
70 |
||
| 431 | 71 |
IriSP.PopcornReplacement.play = function() { |
72 |
IriSP.PopcornReplacement.media.paused = false; |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
73 |
IriSP.PopcornReplacement.trigger("play"); |
| 431 | 74 |
// IriSP.PopcornReplacement.trigger("playing"); |
75 |
jwplayer( IriSP.PopcornReplacement._container ).play(); |
|
| 388 | 76 |
}; |
77 |
|
|
| 431 | 78 |
IriSP.PopcornReplacement.pause = function() { |
79 |
if ( !IriSP.PopcornReplacement.media.paused ) { |
|
80 |
IriSP.PopcornReplacement.media.paused = true; |
|
81 |
IriSP.PopcornReplacement.trigger( "pause" ); |
|
82 |
jwplayer( IriSP.PopcornReplacement._container ).pause(); |
|
| 388 | 83 |
} |
84 |
}; |
|
85 |
||
| 431 | 86 |
IriSP.PopcornReplacement.muted = function(val) { |
| 388 | 87 |
if (typeof(val) !== "undefined") { |
| 390 | 88 |
|
| 431 | 89 |
if (jwplayer(IriSP.PopcornReplacement._container).getMute() !== val) { |
| 390 | 90 |
if (val) { |
| 431 | 91 |
jwplayer(IriSP.PopcornReplacement._container).setMute(true); |
| 388 | 92 |
} else { |
| 431 | 93 |
jwplayer( IriSP.PopcornReplacement._container ).setMute(false); |
| 388 | 94 |
} |
95 |
||
| 431 | 96 |
IriSP.PopcornReplacement.trigger( "volumechange" ); |
| 388 | 97 |
} |
98 |
|
|
| 431 | 99 |
return jwplayer( IriSP.PopcornReplacement._container ).getMute(); |
| 388 | 100 |
} else { |
| 431 | 101 |
return jwplayer( IriSP.PopcornReplacement._container ).getMute(); |
| 388 | 102 |
} |
| 390 | 103 |
}; |
104 |
||
| 431 | 105 |
IriSP.PopcornReplacement.mute = IriSP.PopcornReplacement.muted; |
| 394 | 106 |
|
| 431 | 107 |
IriSP.PopcornReplacement.__codes = []; |
108 |
IriSP.PopcornReplacement.code = function(options) { |
|
109 |
IriSP.PopcornReplacement.__codes.push(options); |
|
110 |
return IriSP.PopcornReplacement; |
|
| 390 | 111 |
}; |
112 |
||
| 431 | 113 |
IriSP.PopcornReplacement.__runCode = function() { |
114 |
var currentTime = jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
|
| 390 | 115 |
var i = 0; |
| 431 | 116 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
117 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
| 391 | 118 |
if (currentTime == c.start) { |
| 390 | 119 |
c.onStart(); |
120 |
} |
|
121 |
|
|
| 391 | 122 |
if (currentTime == c.end) { |
| 390 | 123 |
c.onEnd(); |
124 |
} |
|
| 388 | 125 |
|
| 390 | 126 |
} |
| 394 | 127 |
}; |
| 391 | 128 |
|
| 394 | 129 |
/* called everytime the player updates itself |
130 |
(onTime event) |
|
131 |
*/ |
|
132 |
||
| 431 | 133 |
IriSP.PopcornReplacement.__timeHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
134 |
var pos = event.position; |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
135 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
136 |
var i = 0; |
| 431 | 137 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
138 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
|
417
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 |
if (pos >= c.start && pos < c.end && |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
141 |
pos - 0.1 <= c.start) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
142 |
c.onStart(); |
|
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 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
145 |
if (pos >= c.start && pos >= c.end && |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
146 |
pos - 0.1 <= c.end) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
147 |
c.onEnd(); |
|
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 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
150 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
151 |
|
| 431 | 152 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
| 390 | 153 |
}; |
| 394 | 154 |
|
| 431 | 155 |
IriSP.PopcornReplacement.__seekHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
156 |
var i = 0; |
| 431 | 157 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
158 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
159 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
160 |
if (event.position >= c.start && event.position < c.end) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
161 |
c.onEnd(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
162 |
} |
|
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 (typeof(event.offset) === "undefined") |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
165 |
event.offset = 0; |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
166 |
if (event.offset >= c.start && event.offset < c.end) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
167 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
168 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
169 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
170 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
171 |
|
| 431 | 172 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
173 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
174 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
175 |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
176 |
IriSP.PopcornReplacement.__playHandler = function(event) { |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
177 |
IriSP.PopcornReplacement.media.paused = false; |
| 442 | 178 |
IriSP.PopcornReplacement.trigger("play"); |
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
179 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
180 |
|
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
181 |
IriSP.PopcornReplacement.__pauseHandler = function(event) { |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
182 |
IriSP.PopcornReplacement.media.paused = true; |
| 442 | 183 |
IriSP.PopcornReplacement.trigger("pause"); |
|
441
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 |
|
| 431 | 186 |
IriSP.PopcornReplacement.roundTime = function() { |
187 |
var currentTime = IriSP.PopcornReplacement.currentTime(); |
|
| 394 | 188 |
return Math.round(currentTime); |
189 |
}; |