1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
/**
* Used to Overlay images and take over player controls
*
* extends EmbedPlayerNative object image overlay support
*/
mw.EmbedPlayerImageOverlay = {
instanceOf: 'ImageOverlay',
// If the player is "ready to play"
playerReady : true,
// Pause time used to track player time between pauses
lastPauseTime: 0,
// currentTime updated via internal clockStartTime var
currentTime:0,
// StartOffset support seeking into the virtual player
startOffset:0,
// The local clock used to emulate playback time
clockStartTime: 0,
/**
* Build the player interface:
*/
init: function(){
// Check if features are already updated:
if( this['native_instaceOf'] == 'Native' ){
return ;
}
// inherit mw.EmbedPlayerNative (
for( var i in mw.EmbedPlayerNative ){
if( typeof mw.EmbedPlayerImageOverlay[ i ] != 'undefined' ){
this['native_' + i ] = mw.EmbedPlayerNative[i];
} else {
this[ i ] = mw.EmbedPlayerNative[i];
}
}
},
/**
* When on playback method switch remove imageOverlay
* @param {function} callback
*/
updatePlaybackInterface: function( callback ){
mw.log( 'EmbedPlayerImageOverlay:: updatePlaybackInterface remove imageOverlay: ' + $(this).siblings( '.imageOverlay' ).length );
// Reset lastPauseTime
this.lastPauseTime = 0;
// Clear imageOverlay sibling:
$( this ).find( '.imageOverlay' ).remove();
// Restore the video element on screen position:
$( this.getPlayerElement() ).css('left', 0 );
// Call normal parent updatePlaybackInterface
this.parent_updatePlaybackInterface( callback );
},
/**
* The method called to "show the player"
* For image overlay we want to:
* Set black video urls for player source
* Add an image overlay
*/
updatePosterHTML: function(){
var vid = this.getPlayerElement();
$( vid ).empty()
// Provide modules the opportunity to supply black sources ( for registering event click )
// this is need for iPad to capture the play click to auto continue after "playing an image"
// ( iOS requires a user gesture to initiate video playback )
// We don't just include the sources as part of core config, since it would result in
// a possible privacy leakage i.e hitting the kaltura servers when playing images.
this.triggerHelper( 'AddEmptyBlackSources', [ vid ] );
// embed the image:
this.embedPlayerHTML();
// add the play btn:
this.addLargePlayBtn();
},
/**
* Play function starts the video playback
*/
play: function() {
mw.log( 'EmbedPlayerImageOverlay::play> lastPauseTime:' + this.lastPauseTime + ' ct: ' + this.currentTime );
this.applyIntrinsicAspect();
// Check for image duration
// Reset playback if currentTime > duration:
if( this.currentTime > this.getDuration() ) {
this.currentTime = this.pauseTime = 0;
}
// No longer in a stopped state:
this.stopped = false;
// Capture the play event on the native player: ( should just be black silent sources )
// This is needed so that if a playlist starts with image, it can continue to play the
// subsequent video without on iOS without requiring another click.
if( ! $( this ).data('previousInstanceOf') ){
// Update the previousInstanceOf flag:
$( this ).data('previousInstanceOf', this.instanceOf );
var vid = this.getPlayerElement();
// populate the video with black video sources:
this.triggerHelper( 'AddEmptyBlackSources', [ vid ] );
// run play:
vid.play();
// inline pause
setTimeout(function(){
vid.pause();
},0);
// add another pause request after 500 ms ( iOS sometimes does not listen the first time )
setTimeout(function(){
vid.pause();
}, mw.config.get( 'EmbedPlayer.MonitorRate' ) * 2 );
}
// call the parent play ( to update interface and call respective triggers )
this.parent_play();
// make sure we are in play interface:
this.playInterfaceUpdate();
this.clockStartTime = new Date().getTime();
// Start up monitor:
this.monitor();
},
getDuration: function(){
if( this.duration ){
return this.duration;
}
if( this.imageDuration ){
this.duration = this.imageDuration ;
} else {
this.duration = mw.config.get( "EmbedPlayer.DefaultImageDuration" );
}
// make sure duration has type float:
this.duration = parseFloat( this.duration );
return this.duration;
},
/**
* Stops the playback
*/
stop: function() {
this.currentTime = 0;
this.parent_stop();
},
_onpause: function(){
// catch the native event ( and do nothing )
},
/**
* Preserves the pause time across for timed playback
*/
pause: function( ) {
this.lastPauseTime = this.currentTime;
mw.log( 'EmbedPlayerImageOverlay::pause, lastPauseTime: ' + this.lastPauseTime );
// run parent pause;
this.parent_pause();
this.stopMonitor();
},
monitor: function(){
if( this.duration == 0 ){
this.disablePlayControls();
return ;
}
$( this ).trigger( 'timeupdate' );
if ( this.currentTime >= this.duration ) {
$( this ).trigger( 'ended' );
} else {
// Run the parent monitor:
this.parent_monitor();
}
},
/**
* Seeks to a given percent and updates the lastPauseTime
*
* @param {Float} seekPercent Percentage to seek into the virtual player
*/
seek: function( seekPercent ) {
this.lastPauseTime = seekPercent * this.getDuration();
this.seeking = false;
// start seeking:
$( this ).trigger( 'seeking' );
// Done seeking
$( this ).trigger( 'seeked' );
this.play();
},
/**
* Sets the current Time
*
* @param {Float} perc Percentage to seek into the virtual player
* @param {Function} callback Function called once time has been updated
*/
setCurrentTime: function( time, callback ) {
this.lastPauseTime = time;
// start seeking:
$( this ).trigger( 'seeking' );
// Done seeking
$( this ).trigger( 'seeked' );
if( callback ){
callback();
}
},
/**
* Switch the image playback
*/
playerSwitchSource: function( source, switchCallback, doneCallback ){
var _this = this;
this.selectedSource = source;
this.embedPlayerHTML();
this.applyIntrinsicAspect();
this.play();
if( switchCallback ){
switchCallback( this );
}
// Wait for ended event to tr
$( this ).bind('ended.playerSwitchSource', function(){
$( _this ).unbind('ended.playerSwitchSource');
if( doneCallback ) {
doneCallback( this );
}
})
},
/**
* Get the embed player time
*/
getPlayerElementTime: function() {
this.currentTime = ( ( new Date().getTime() - this.clockStartTime ) / 1000 ) + this.lastPauseTime;
return this.currentTime;
},
/**
* Get the "embed" html for the html player
*/
embedPlayerHTML: function() {
var _this = this;
// remove any old imageOverlay:
this.$interface.find('.imageOverlay').remove();
mw.log( 'EmbedPlayerImageOverlay :doEmbedHTML: ' + this.id );
var currentSoruceObj = this.selectedSource;
if( !currentSoruceObj ){
mw.log("Error:: EmbedPlayerImageOverlay:embedPlayerHTML> missing source" );
return ;
}
var $image =
$( '<img />' )
.css({
'position': 'relative',
'width': '100%',
'height': '100%'
})
.attr({
'src' : currentSoruceObj.getSrc()
})
.addClass( 'imageOverlay' )
.load( function(){
// reset clock time:
_this.clockStartTime = new Date().getTime();
_this.monitor();
})
// move the video element off screen:
$( this.getPlayerElement() ).css({
'left': this.getWidth()+50,
'position' : 'absolute'
});
// Add the image before the video element or before the playerInterface
$( this ).html( $image );
this.applyIntrinsicAspect();
},
// wrap the parent rewize player to apply intensic apsect
resizePlayer: function( size , animate, callback){
this.parent_resizePlayer( size , animate, callback );
this.applyIntrinsicAspect();
},
applyIntrinsicAspect: function(){
var $this = this.$interface;
// Check if a image thumbnail is present:
/*if( this.$interface && this.$interface.find('.imageOverlay').length ){
var img = this.$interface.find('.imageOverlay')[0];
var pHeight = $this.height();
// Check for intrinsic width and maintain aspect ratio
if( img.naturalWidth && img.naturalHeight ){
var pWidth = parseInt( img.naturalWidth / img.naturalHeight * pHeight);
if( pWidth > $this.width() ){
pWidth = $this.width();
pHeight = parseInt( img.naturalHeight / img.naturalWidth * pWidth );
}
$( img ).css({
'height' : pHeight + 'px',
'width': pWidth + 'px',
'left': ( ( $this.width() - pWidth ) * .5 ) + 'px',
'top': ( ( $this.height() - pHeight ) * .5 ) + 'px',
'position' : 'absolute'
});
}
}*/
}
};
|