| author | hamidouk |
| Wed, 07 Dec 2011 11:51:04 +0100 | |
| branch | no-popcorn |
| changeset 417 | bae7c50704d7 |
| parent 394 | 89a79a2c6014 |
| child 419 | fe7e46eda1b4 |
| permissions | -rw-r--r-- |
| 387 | 1 |
/* wrapper that simulates popcorn.js because |
2 |
popcorn is a bit unstable at the time */ |
|
| 388 | 3 |
|
4 |
Popcorn = {}; |
|
| 394 | 5 |
Popcorn.media = { "paused": true}; |
| 390 | 6 |
|
| 388 | 7 |
Popcorn.listen = function(msg, callback) { |
| 394 | 8 |
IriSP.jQuery(Popcorn).bind(msg, function(event, rest) { callback(rest); }); |
| 388 | 9 |
}; |
10 |
||
11 |
Popcorn.trigger = function(msg, params) { |
|
| 394 | 12 |
IriSP.jQuery(Popcorn).trigger(msg, params); |
| 388 | 13 |
}; |
14 |
||
15 |
Popcorn.guid = function(prefix) { |
|
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 |
||
24 |
Popcorn.__initApi = function() { |
|
25 |
Popcorn.trigger("timeupdate"); |
|
26 |
}; |
|
27 |
||
28 |
Popcorn.jwplayer = function(container, options) { |
|
| 390 | 29 |
Popcorn._container = container.slice(1); //eschew the '#' |
| 388 | 30 |
options.events = { |
| 390 | 31 |
onReady: Popcorn.__initApi, |
| 394 | 32 |
onTime: Popcorn.__timeHandler, |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
33 |
onSeek: Popcorn.__seekHandler } |
| 388 | 34 |
|
35 |
jwplayer(Popcorn._container).setup(options); |
|
| 391 | 36 |
Popcorn.media.duration = options.duration; |
| 390 | 37 |
return Popcorn; |
| 388 | 38 |
}; |
39 |
||
40 |
Popcorn.currentTime = function(time) { |
|
41 |
if (typeof(time) === "undefined") { |
|
42 |
return jwplayer(Popcorn._container).getPosition(); |
|
43 |
} else { |
|
44 |
var currentTime = +time; |
|
45 |
jwplayer( Popcorn._container ).seek( currentTime ); |
|
46 |
return jwplayer(Popcorn._container).getPosition(); |
|
47 |
} |
|
48 |
}; |
|
49 |
||
50 |
Popcorn.play = function() { |
|
| 390 | 51 |
Popcorn.media.paused = false; |
| 394 | 52 |
// Popcorn.trigger("play"); |
53 |
// Popcorn.trigger("playing"); |
|
| 388 | 54 |
jwplayer( Popcorn._container ).play(); |
55 |
}; |
|
56 |
|
|
57 |
Popcorn.pause = function() { |
|
| 390 | 58 |
if ( !Popcorn.media.paused ) { |
59 |
Popcorn.media.paused = true; |
|
| 388 | 60 |
Popcorn.trigger( "pause" ); |
61 |
jwplayer( Popcorn._container ).pause(); |
|
62 |
} |
|
63 |
}; |
|
64 |
||
65 |
Popcorn.muted = function(val) { |
|
66 |
if (typeof(val) !== "undefined") { |
|
| 390 | 67 |
|
68 |
if (jwplayer(Popcorn._container).getMute() !== val) { |
|
69 |
if (val) { |
|
70 |
jwplayer(Popcorn._container).setMute(true); |
|
| 388 | 71 |
} else { |
72 |
jwplayer( Popcorn._container ).setMute(false); |
|
73 |
} |
|
74 |
||
| 394 | 75 |
Popcorn.trigger( "volumechange" ); |
| 388 | 76 |
} |
77 |
|
|
78 |
return jwplayer( Popcorn._container ).getMute(); |
|
79 |
} else { |
|
80 |
return jwplayer( Popcorn._container ).getMute(); |
|
81 |
} |
|
| 390 | 82 |
}; |
83 |
||
| 394 | 84 |
Popcorn.mute = Popcorn.muted; |
85 |
||
| 390 | 86 |
Popcorn.__codes = []; |
87 |
Popcorn.code = function(options) { |
|
88 |
Popcorn.__codes.push(options); |
|
89 |
return Popcorn; |
|
90 |
}; |
|
91 |
||
| 394 | 92 |
Popcorn.__runCode = function() { |
| 390 | 93 |
var currentTime = jwplayer(Popcorn._container).getPosition(); |
94 |
var i = 0; |
|
95 |
for(i = 0; i < Popcorn.__codes.length; i++) { |
|
96 |
var c = Popcorn.__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 |
||
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
112 |
Popcorn.__timeHandler = function(event) { |
|
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; |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
116 |
for(i = 0; i < Popcorn.__codes.length; i++) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
117 |
var c = Popcorn.__codes[i]; |
|
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 |
|
| 391 | 131 |
Popcorn.trigger("timeupdate"); |
| 390 | 132 |
}; |
| 394 | 133 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
134 |
Popcorn.__seekHandler = function(event) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
135 |
var i = 0; |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
136 |
for(i = 0; i < Popcorn.__codes.length; i++) { |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
137 |
var c = Popcorn.__codes[i]; |
|
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 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
151 |
Popcorn.trigger("timeupdate"); |
|
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 |
|
| 394 | 155 |
Popcorn.roundTime = function() { |
156 |
var currentTime = Popcorn.currentTime(); |
|
157 |
return Math.round(currentTime); |
|
158 |
}; |