|
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, |
|
|
33 |
onSeek: function(event) { |
|
|
34 |
var i = 0; |
|
|
35 |
console.log("old: %d, new: %d", event.position, event.offset); |
|
|
36 |
for(i = 0; i < Popcorn.__codes.length; i++) { |
|
|
37 |
var c = Popcorn.__codes[i]; |
|
|
38 |
|
|
|
39 |
if (event.position >= c.start && event.position < c.end) { |
|
|
40 |
c.onEnd(); |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
if (typeof(event.offset) === "undefined") |
|
|
44 |
event.offset = 0; |
|
|
45 |
if (event.offset >= c.start && event.offset < c.end) { |
|
|
46 |
c.onStart(); |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
Popcorn.trigger("timeupdate"); |
|
|
52 |
} |
|
|
53 |
} |
|
388
|
54 |
|
|
|
55 |
jwplayer(Popcorn._container).setup(options); |
|
391
|
56 |
Popcorn.media.duration = options.duration; |
|
390
|
57 |
return Popcorn; |
|
388
|
58 |
}; |
|
|
59 |
|
|
|
60 |
Popcorn.currentTime = function(time) { |
|
|
61 |
if (typeof(time) === "undefined") { |
|
|
62 |
return jwplayer(Popcorn._container).getPosition(); |
|
|
63 |
} else { |
|
|
64 |
var currentTime = +time; |
|
|
65 |
jwplayer( Popcorn._container ).seek( currentTime ); |
|
|
66 |
return jwplayer(Popcorn._container).getPosition(); |
|
|
67 |
} |
|
|
68 |
}; |
|
|
69 |
|
|
|
70 |
Popcorn.play = function() { |
|
390
|
71 |
Popcorn.media.paused = false; |
|
394
|
72 |
// Popcorn.trigger("play"); |
|
|
73 |
// Popcorn.trigger("playing"); |
|
388
|
74 |
jwplayer( Popcorn._container ).play(); |
|
|
75 |
}; |
|
|
76 |
|
|
|
77 |
Popcorn.pause = function() { |
|
390
|
78 |
if ( !Popcorn.media.paused ) { |
|
|
79 |
Popcorn.media.paused = true; |
|
388
|
80 |
Popcorn.trigger( "pause" ); |
|
|
81 |
jwplayer( Popcorn._container ).pause(); |
|
|
82 |
} |
|
|
83 |
}; |
|
|
84 |
|
|
|
85 |
Popcorn.muted = function(val) { |
|
|
86 |
if (typeof(val) !== "undefined") { |
|
390
|
87 |
|
|
|
88 |
if (jwplayer(Popcorn._container).getMute() !== val) { |
|
|
89 |
if (val) { |
|
|
90 |
jwplayer(Popcorn._container).setMute(true); |
|
388
|
91 |
} else { |
|
|
92 |
jwplayer( Popcorn._container ).setMute(false); |
|
|
93 |
} |
|
|
94 |
|
|
394
|
95 |
Popcorn.trigger( "volumechange" ); |
|
388
|
96 |
} |
|
|
97 |
|
|
|
98 |
return jwplayer( Popcorn._container ).getMute(); |
|
|
99 |
} else { |
|
|
100 |
return jwplayer( Popcorn._container ).getMute(); |
|
|
101 |
} |
|
390
|
102 |
}; |
|
|
103 |
|
|
394
|
104 |
Popcorn.mute = Popcorn.muted; |
|
|
105 |
|
|
390
|
106 |
Popcorn.__codes = []; |
|
|
107 |
Popcorn.code = function(options) { |
|
|
108 |
Popcorn.__codes.push(options); |
|
|
109 |
return Popcorn; |
|
|
110 |
}; |
|
|
111 |
|
|
394
|
112 |
Popcorn.__runCode = function() { |
|
390
|
113 |
var currentTime = jwplayer(Popcorn._container).getPosition(); |
|
|
114 |
var i = 0; |
|
|
115 |
for(i = 0; i < Popcorn.__codes.length; i++) { |
|
|
116 |
var c = Popcorn.__codes[i]; |
|
391
|
117 |
if (currentTime == c.start) { |
|
390
|
118 |
c.onStart(); |
|
|
119 |
} |
|
|
120 |
|
|
391
|
121 |
if (currentTime == c.end) { |
|
390
|
122 |
c.onEnd(); |
|
|
123 |
} |
|
388
|
124 |
|
|
390
|
125 |
} |
|
394
|
126 |
}; |
|
391
|
127 |
|
|
394
|
128 |
/* called everytime the player updates itself |
|
|
129 |
(onTime event) |
|
|
130 |
*/ |
|
|
131 |
|
|
|
132 |
Popcorn.__timeHandler = function() { |
|
391
|
133 |
Popcorn.trigger("timeupdate"); |
|
390
|
134 |
}; |
|
394
|
135 |
|
|
|
136 |
Popcorn.roundTime = function() { |
|
|
137 |
var currentTime = Popcorn.currentTime(); |
|
|
138 |
return Math.round(currentTime); |
|
|
139 |
}; |