1 /* wrapper that simulates popcorn.js because |
1 /* wrapper that simulates popcorn.js because |
2 popcorn is a bit unstable at the time */ |
2 popcorn is a bit unstable at the time */ |
3 |
3 |
4 Popcorn = {}; |
4 PopcornReplacement = {}; |
5 Popcorn.media = { "paused": true}; |
5 PopcornReplacement.media = { "paused": true}; |
6 |
6 |
7 Popcorn.listen = function(msg, callback) { |
7 PopcornReplacement.listen = function(msg, callback) { |
8 IriSP.jQuery(Popcorn).bind(msg, function(event, rest) { callback(rest); }); |
8 IriSP.jQuery(PopcornReplacement).bind(msg, function(event, rest) { callback(rest); }); |
9 }; |
9 }; |
10 |
10 |
11 Popcorn.trigger = function(msg, params) { |
11 PopcornReplacement.trigger = function(msg, params) { |
12 IriSP.jQuery(Popcorn).trigger(msg, params); |
12 IriSP.jQuery(PopcornReplacement).trigger(msg, params); |
13 }; |
13 }; |
14 |
14 |
15 Popcorn.guid = function(prefix) { |
15 PopcornReplacement.guid = function(prefix) { |
16 var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
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); |
17 var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
18 return v.toString(16); |
18 return v.toString(16); |
19 }); |
19 }); |
20 |
20 |
21 return prefix + str; |
21 return prefix + str; |
22 }; |
22 }; |
23 |
23 |
24 Popcorn.__initApi = function() { |
24 PopcornReplacement.__initApi = function() { |
25 Popcorn.trigger("timeupdate"); |
25 PopcornReplacement.trigger("timeupdate"); |
26 }; |
26 }; |
27 |
27 |
28 Popcorn.jwplayer = function(container, options) { |
28 PopcornReplacement.jwplayer = function(container, options) { |
29 Popcorn._container = container.slice(1); //eschew the '#' |
29 PopcornReplacement._container = container.slice(1); //eschew the '#' |
30 options.events = { |
30 options.events = { |
31 onReady: Popcorn.__initApi, |
31 onReady: PopcornReplacement.__initApi, |
32 onTime: Popcorn.__timeHandler, |
32 onTime: PopcornReplacement.__timeHandler, |
33 onSeek: Popcorn.__seekHandler } |
33 onSeek: PopcornReplacement.__seekHandler } |
34 |
34 |
35 jwplayer(Popcorn._container).setup(options); |
35 jwplayer(PopcornReplacement._container).setup(options); |
36 Popcorn.media.duration = options.duration; |
36 PopcornReplacement.media.duration = options.duration; |
37 return Popcorn; |
37 return PopcornReplacement; |
38 }; |
38 }; |
39 |
39 |
40 Popcorn.currentTime = function(time) { |
40 PopcornReplacement.currentTime = function(time) { |
41 if (typeof(time) === "undefined") { |
41 if (typeof(time) === "undefined") { |
42 return jwplayer(Popcorn._container).getPosition(); |
42 return jwplayer(PopcornReplacement._container).getPosition(); |
43 } else { |
43 } else { |
44 var currentTime = +time; |
44 var currentTime = +time; |
45 jwplayer( Popcorn._container ).seek( currentTime ); |
45 jwplayer( PopcornReplacement._container ).seek( currentTime ); |
46 return jwplayer(Popcorn._container).getPosition(); |
46 return jwplayer(PopcornReplacement._container).getPosition(); |
47 } |
47 } |
48 }; |
48 }; |
49 |
49 |
50 Popcorn.play = function() { |
50 PopcornReplacement.play = function() { |
51 Popcorn.media.paused = false; |
51 PopcornReplacement.media.paused = false; |
52 // Popcorn.trigger("play"); |
52 // PopcornReplacement.trigger("play"); |
53 // Popcorn.trigger("playing"); |
53 // PopcornReplacement.trigger("playing"); |
54 jwplayer( Popcorn._container ).play(); |
54 jwplayer( PopcornReplacement._container ).play(); |
55 }; |
55 }; |
56 |
56 |
57 Popcorn.pause = function() { |
57 PopcornReplacement.pause = function() { |
58 if ( !Popcorn.media.paused ) { |
58 if ( !PopcornReplacement.media.paused ) { |
59 Popcorn.media.paused = true; |
59 PopcornReplacement.media.paused = true; |
60 Popcorn.trigger( "pause" ); |
60 PopcornReplacement.trigger( "pause" ); |
61 jwplayer( Popcorn._container ).pause(); |
61 jwplayer( PopcornReplacement._container ).pause(); |
62 } |
62 } |
63 }; |
63 }; |
64 |
64 |
65 Popcorn.muted = function(val) { |
65 PopcornReplacement.muted = function(val) { |
66 if (typeof(val) !== "undefined") { |
66 if (typeof(val) !== "undefined") { |
67 |
67 |
68 if (jwplayer(Popcorn._container).getMute() !== val) { |
68 if (jwplayer(PopcornReplacement._container).getMute() !== val) { |
69 if (val) { |
69 if (val) { |
70 jwplayer(Popcorn._container).setMute(true); |
70 jwplayer(PopcornReplacement._container).setMute(true); |
71 } else { |
71 } else { |
72 jwplayer( Popcorn._container ).setMute(false); |
72 jwplayer( PopcornReplacement._container ).setMute(false); |
73 } |
73 } |
74 |
74 |
75 Popcorn.trigger( "volumechange" ); |
75 PopcornReplacement.trigger( "volumechange" ); |
76 } |
76 } |
77 |
77 |
78 return jwplayer( Popcorn._container ).getMute(); |
78 return jwplayer( PopcornReplacement._container ).getMute(); |
79 } else { |
79 } else { |
80 return jwplayer( Popcorn._container ).getMute(); |
80 return jwplayer( PopcornReplacement._container ).getMute(); |
81 } |
81 } |
82 }; |
82 }; |
83 |
83 |
84 Popcorn.mute = Popcorn.muted; |
84 PopcornReplacement.mute = PopcornReplacement.muted; |
85 |
85 |
86 Popcorn.__codes = []; |
86 PopcornReplacement.__codes = []; |
87 Popcorn.code = function(options) { |
87 PopcornReplacement.code = function(options) { |
88 Popcorn.__codes.push(options); |
88 PopcornReplacement.__codes.push(options); |
89 return Popcorn; |
89 return PopcornReplacement; |
90 }; |
90 }; |
91 |
91 |
92 Popcorn.__runCode = function() { |
92 PopcornReplacement.__runCode = function() { |
93 var currentTime = jwplayer(Popcorn._container).getPosition(); |
93 var currentTime = jwplayer(PopcornReplacement._container).getPosition(); |
94 var i = 0; |
94 var i = 0; |
95 for(i = 0; i < Popcorn.__codes.length; i++) { |
95 for(i = 0; i < PopcornReplacement.__codes.length; i++) { |
96 var c = Popcorn.__codes[i]; |
96 var c = PopcornReplacement.__codes[i]; |
97 if (currentTime == c.start) { |
97 if (currentTime == c.start) { |
98 c.onStart(); |
98 c.onStart(); |
99 } |
99 } |
100 |
100 |
101 if (currentTime == c.end) { |
101 if (currentTime == c.end) { |