|
387
|
1 |
/* wrapper that simulates popcorn.js because |
|
|
2 |
popcorn is a bit unstable at the time */ |
|
388
|
3 |
|
|
|
4 |
Popcorn = {}; |
|
390
|
5 |
Popcorn.media = {}; |
|
|
6 |
|
|
388
|
7 |
Popcorn.listen = function(msg, callback) { |
|
|
8 |
IriSP.jQuery(Popcorn).bind(msg, callback); |
|
|
9 |
}; |
|
|
10 |
|
|
|
11 |
Popcorn.trigger = function(msg, params) { |
|
|
12 |
IriSP.jQuery(msg, params); |
|
|
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, |
|
|
32 |
onTime: Popcorn.__timehandler |
|
388
|
33 |
}; |
|
|
34 |
|
|
|
35 |
jwplayer(Popcorn._container).setup(options); |
|
390
|
36 |
return Popcorn; |
|
388
|
37 |
}; |
|
|
38 |
|
|
|
39 |
Popcorn.currentTime = function(time) { |
|
|
40 |
if (typeof(time) === "undefined") { |
|
|
41 |
return jwplayer(Popcorn._container).getPosition(); |
|
|
42 |
} else { |
|
|
43 |
var currentTime = +time; |
|
390
|
44 |
Popcorn.trigger("seeked"); |
|
|
45 |
Popcorn.trigger("timeupdate"); |
|
388
|
46 |
jwplayer( Popcorn._container ).seek( currentTime ); |
|
|
47 |
return jwplayer(Popcorn._container).getPosition(); |
|
|
48 |
} |
|
|
49 |
}; |
|
|
50 |
|
|
|
51 |
Popcorn.play = function() { |
|
390
|
52 |
Popcorn.media.paused = false; |
|
388
|
53 |
Popcorn.trigger("play"); |
|
|
54 |
Popcorn.trigger("playing"); |
|
|
55 |
jwplayer( Popcorn._container ).play(); |
|
|
56 |
}; |
|
|
57 |
|
|
|
58 |
Popcorn.pause = function() { |
|
390
|
59 |
if ( !Popcorn.media.paused ) { |
|
|
60 |
Popcorn.media.paused = true; |
|
388
|
61 |
Popcorn.trigger( "pause" ); |
|
|
62 |
jwplayer( Popcorn._container ).pause(); |
|
|
63 |
} |
|
|
64 |
}; |
|
|
65 |
|
|
|
66 |
Popcorn.muted = function(val) { |
|
|
67 |
if (typeof(val) !== "undefined") { |
|
390
|
68 |
|
|
|
69 |
if (jwplayer(Popcorn._container).getMute() !== val) { |
|
|
70 |
if (val) { |
|
|
71 |
jwplayer(Popcorn._container).setMute(true); |
|
388
|
72 |
} else { |
|
|
73 |
jwplayer( Popcorn._container ).setMute(false); |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
media.dispatchEvent( "volumechange" ); |
|
|
77 |
} |
|
|
78 |
|
|
|
79 |
return jwplayer( Popcorn._container ).getMute(); |
|
|
80 |
} else { |
|
|
81 |
return jwplayer( Popcorn._container ).getMute(); |
|
|
82 |
} |
|
390
|
83 |
}; |
|
|
84 |
|
|
|
85 |
Popcorn.__codes = []; |
|
|
86 |
Popcorn.code = function(options) { |
|
|
87 |
Popcorn.__codes.push(options); |
|
|
88 |
return Popcorn; |
|
|
89 |
}; |
|
|
90 |
|
|
|
91 |
/* called everytime the player updates itself |
|
|
92 |
(onTime event) |
|
|
93 |
*/ |
|
388
|
94 |
|
|
390
|
95 |
Popcorn.__timehandler = function() { |
|
|
96 |
var currentTime = jwplayer(Popcorn._container).getPosition(); |
|
|
97 |
var i = 0; |
|
|
98 |
for(i = 0; i < Popcorn.__codes.length; i++) { |
|
|
99 |
var c = Popcorn.__codes[i]; |
|
|
100 |
if (currentTime <= c.start && currentTime + 0.1 >= c.start) { |
|
|
101 |
c.onStart(); |
|
|
102 |
} |
|
|
103 |
|
|
|
104 |
if (currentTime <= c.end && currentTime + 0.1 >= c.end) { |
|
|
105 |
c.onEnd(); |
|
|
106 |
} |
|
388
|
107 |
|
|
390
|
108 |
} |
|
|
109 |
}; |