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