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