| author | hamidouk |
| Thu, 08 Dec 2011 12:29:56 +0100 | |
| branch | bugslaying-after-r417-merge |
| changeset 431 | f9460dc1957f |
| parent 419 | fe7e46eda1b4 |
| child 441 | 99b7c5192330 |
| 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) { |
12 |
IriSP.jQuery(IriSP.PopcornReplacement).trigger(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, |
|
33 |
onSeek: IriSP.PopcornReplacement.__seekHandler } |
|
| 388 | 34 |
|
| 431 | 35 |
jwplayer(IriSP.PopcornReplacement._container).setup(options); |
36 |
IriSP.PopcornReplacement.media.duration = options.duration; |
|
37 |
return IriSP.PopcornReplacement; |
|
| 388 | 38 |
}; |
39 |
||
| 431 | 40 |
IriSP.PopcornReplacement.currentTime = function(time) { |
| 388 | 41 |
if (typeof(time) === "undefined") { |
| 431 | 42 |
return jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
| 388 | 43 |
} else { |
44 |
var currentTime = +time; |
|
| 431 | 45 |
jwplayer( IriSP.PopcornReplacement._container ).seek( currentTime ); |
46 |
return jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
|
| 388 | 47 |
} |
48 |
}; |
|
49 |
||
| 431 | 50 |
IriSP.PopcornReplacement.play = function() { |
51 |
IriSP.PopcornReplacement.media.paused = false; |
|
52 |
// IriSP.PopcornReplacement.trigger("play"); |
|
53 |
// IriSP.PopcornReplacement.trigger("playing"); |
|
54 |
jwplayer( IriSP.PopcornReplacement._container ).play(); |
|
| 388 | 55 |
}; |
56 |
|
|
| 431 | 57 |
IriSP.PopcornReplacement.pause = function() { |
58 |
if ( !IriSP.PopcornReplacement.media.paused ) { |
|
59 |
IriSP.PopcornReplacement.media.paused = true; |
|
60 |
IriSP.PopcornReplacement.trigger( "pause" ); |
|
61 |
jwplayer( IriSP.PopcornReplacement._container ).pause(); |
|
| 388 | 62 |
} |
63 |
}; |
|
64 |
||
| 431 | 65 |
IriSP.PopcornReplacement.muted = function(val) { |
| 388 | 66 |
if (typeof(val) !== "undefined") { |
| 390 | 67 |
|
| 431 | 68 |
if (jwplayer(IriSP.PopcornReplacement._container).getMute() !== val) { |
| 390 | 69 |
if (val) { |
| 431 | 70 |
jwplayer(IriSP.PopcornReplacement._container).setMute(true); |
| 388 | 71 |
} else { |
| 431 | 72 |
jwplayer( IriSP.PopcornReplacement._container ).setMute(false); |
| 388 | 73 |
} |
74 |
||
| 431 | 75 |
IriSP.PopcornReplacement.trigger( "volumechange" ); |
| 388 | 76 |
} |
77 |
|
|
| 431 | 78 |
return jwplayer( IriSP.PopcornReplacement._container ).getMute(); |
| 388 | 79 |
} else { |
| 431 | 80 |
return jwplayer( IriSP.PopcornReplacement._container ).getMute(); |
| 388 | 81 |
} |
| 390 | 82 |
}; |
83 |
||
| 431 | 84 |
IriSP.PopcornReplacement.mute = IriSP.PopcornReplacement.muted; |
| 394 | 85 |
|
| 431 | 86 |
IriSP.PopcornReplacement.__codes = []; |
87 |
IriSP.PopcornReplacement.code = function(options) { |
|
88 |
IriSP.PopcornReplacement.__codes.push(options); |
|
89 |
return IriSP.PopcornReplacement; |
|
| 390 | 90 |
}; |
91 |
||
| 431 | 92 |
IriSP.PopcornReplacement.__runCode = function() { |
93 |
var currentTime = jwplayer(IriSP.PopcornReplacement._container).getPosition(); |
|
| 390 | 94 |
var i = 0; |
| 431 | 95 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
96 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
| 391 | 97 |
if (currentTime == c.start) { |
| 390 | 98 |
c.onStart(); |
99 |
} |
|
100 |
|
|
| 391 | 101 |
if (currentTime == c.end) { |
| 390 | 102 |
c.onEnd(); |
103 |
} |
|
| 388 | 104 |
|
| 390 | 105 |
} |
| 394 | 106 |
}; |
| 391 | 107 |
|
| 394 | 108 |
/* called everytime the player updates itself |
109 |
(onTime event) |
|
110 |
*/ |
|
111 |
||
| 431 | 112 |
IriSP.PopcornReplacement.__timeHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
113 |
var pos = event.position; |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
114 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
115 |
var i = 0; |
| 431 | 116 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
117 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
118 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
119 |
if (pos >= c.start && pos < c.end && |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
120 |
pos - 0.1 <= c.start) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
121 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
122 |
} |
|
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.end) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
126 |
c.onEnd(); |
|
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 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
130 |
|
| 431 | 131 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
| 390 | 132 |
}; |
| 394 | 133 |
|
| 431 | 134 |
IriSP.PopcornReplacement.__seekHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
135 |
var i = 0; |
| 431 | 136 |
for(i = 0; i < IriSP.PopcornReplacement.__codes.length; i++) { |
137 |
var c = IriSP.PopcornReplacement.__codes[i]; |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
138 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
139 |
if (event.position >= c.start && event.position < c.end) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
140 |
c.onEnd(); |
|
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 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
143 |
if (typeof(event.offset) === "undefined") |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
144 |
event.offset = 0; |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
145 |
if (event.offset >= c.start && event.offset < c.end) { |
|
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 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
150 |
|
| 431 | 151 |
IriSP.PopcornReplacement.trigger("timeupdate"); |
|
417
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 |
|
| 431 | 155 |
IriSP.PopcornReplacement.roundTime = function() { |
156 |
var currentTime = IriSP.PopcornReplacement.currentTime(); |
|
| 394 | 157 |
return Math.round(currentTime); |
158 |
}; |