r84987 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84986‎ | r84987 | r84988 >
Date:22:30, 29 March 2011
Author:dale
Status:deferred
Tags:
Comment:
fixed issues with lack of Timed Media Handler global exposure of local methods. Fixes usage of resource loader in non-debug mode
Modified paths:
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/EmbedPlayer.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/MediaElement.js (deleted) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/MediaPlayer.js (deleted) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/MediaPlayers.js (deleted) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/MediaSource.js (deleted) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayer.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedTypes.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js (added) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaPlayer.js (added) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaPlayers.js (added) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaSource.js (added) (history)

Diff [purge]

Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/EmbedPlayer.php
@@ -1,17 +1,18 @@
22 <?php
3 -
43 // Register all the EmbedPlayer modules
54 return array(
6 - "MediaElement" => array( 'scripts' => 'resources/MediaElement.js' ),
7 - "MediaPlayer" => array( 'scripts' => 'resources/MediaPlayer.js' ),
8 - "MediaPlayers" => array(
9 - 'scripts' => 'resources/MediaPlayers.js',
10 - 'dependencies' => 'MediaPlayer'
 5+ "mw.MediaElement" => array( 'scripts' => 'resources/mw.MediaElement.js' ),
 6+ "mw.MediaPlayer" => array( 'scripts' => 'resources/mw.MediaPlayer.js' ),
 7+ "mw.MediaPlayers" => array(
 8+ 'scripts' => 'resources/mw.MediaPlayers.js',
 9+ 'dependencies' => 'mw.MediaPlayer'
1110 ),
12 - "MediaSource" => array( 'scripts' => 'resources/MediaSource.js' ),
 11+ "mw.MediaSource" => array( 'scripts' => 'resources/mw.MediaSource.js' ),
1312 "mw.EmbedTypes" => array(
1413 'scripts' => 'resources/mw.EmbedTypes.js',
15 - 'dependencies' => 'MediaPlayers'
 14+ 'dependencies' => array(
 15+ 'mw.MediaPlayers'
 16+ )
1617 ),
1718
1819 "mw.EmbedPlayer" => array(
@@ -28,9 +29,9 @@
2930 'mediawiki.absoluteUrl',
3031
3132 // Sub classes:
32 - 'MediaElement',
33 - 'MediaPlayers',
34 - 'MediaSource',
 33+ 'mw.MediaElement',
 34+ 'mw.MediaPlayers',
 35+ 'mw.MediaSource',
3536 'mw.EmbedTypes',
3637
3738 // jQuery dependencies:
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/MediaElement.js
@@ -1,394 +0,0 @@
2 -/**
3 - * A media element corresponding to a <video> element.
4 - *
5 - * It is implemented as a collection of mediaSource objects. The media sources
6 - * will be initialized from the <video> element, its child <source> elements,
7 - * and/or the ROE file referenced by the <video> element.
8 - *
9 - * @param {element}
10 - * videoElement <video> element used for initialization.
11 - * @constructor
12 - */
13 -function mediaElement( element ) {
14 - this.init( element );
15 -}
16 -
17 -mediaElement.prototype = {
18 -
19 - // The array of mediaSource elements.
20 - sources: null,
21 -
22 - // flag for ROE data being added.
23 - addedROEData: false,
24 -
25 - // Selected mediaSource element.
26 - selectedSource: null,
27 -
28 - /**
29 - * Media Element constructor
30 - *
31 - * Sets up a mediaElement from a provided top level "video" element adds any
32 - * child sources that are found
33 - *
34 - * @param {Element}
35 - * videoElement Element that has src attribute or has children
36 - * source elements
37 - */
38 - init: function( videoElement ) {
39 - var _this = this;
40 - mw.log( "EmbedPlayer::mediaElement:init:" + videoElement.id );
41 - this.parentEmbedId = videoElement.id;
42 - this.sources = new Array();
43 -
44 - // Process the videoElement as a source element:
45 - if ( $( videoElement ).attr( "src" ) ) {
46 - _this.tryAddSource( videoElement );
47 - }
48 -
49 - // Process elements source children
50 - $( videoElement ).find( 'source,track' ).each( function( ) {
51 - _this.tryAddSource( this );
52 - } );
53 - },
54 -
55 - /**
56 - * Updates the time request for all sources that have a standard time
57 - * request argument (ie &t=start_time/end_time)
58 - *
59 - * @param {String}
60 - * start_npt Start time in npt format
61 - * @param {String}
62 - * end_npt End time in npt format
63 - */
64 - updateSourceTimes: function( start_npt, end_npt ) {
65 - var _this = this;
66 - $.each( this.sources, function( inx, mediaSource ) {
67 - mediaSource.updateSrcTime( start_npt, end_npt );
68 - } );
69 - },
70 -
71 - /**
72 - * Check for Timed Text tracks
73 - *
74 - * @return {Boolean} True if text tracks exist, false if no text tracks are
75 - * found
76 - */
77 - textSourceExists: function() {
78 - for ( var i = 0; i < this.sources.length; i++ ) {
79 - if ( this.sources[i].mimeType == 'text/cmml' ||
80 - this.sources[i].mimeType == 'text/x-srt' )
81 - {
82 - return true;
83 - }
84 - };
85 - return false;
86 - },
87 -
88 - /**
89 - * Returns the array of mediaSources of this element.
90 - *
91 - * @param {String}
92 - * [mimeFilter] Filter criteria for set of mediaSources to return
93 - * @return {Array} mediaSource elements.
94 - */
95 - getSources: function( mimeFilter ) {
96 - if ( !mimeFilter ) {
97 - return this.sources;
98 - }
99 - // Apply mime filter:
100 - var source_set = new Array();
101 - for ( var i = 0; i < this.sources.length ; i++ ) {
102 - if ( this.sources[i].mimeType &&
103 - this.sources[i].mimeType.indexOf( mimeFilter ) != -1 )
104 - {
105 - source_set.push( this.sources[i] );
106 - }
107 - }
108 - return source_set;
109 - },
110 -
111 - /**
112 - * Selects a source by id
113 - *
114 - * @param {String}
115 - * source_id Id of the source to select.
116 - * @return {MediaSource} The selected mediaSource or null if not found
117 - */
118 - getSourceById:function( sourceId ) {
119 - for ( var i = 0; i < this.sources.length ; i++ ) {
120 - if ( this.sources[i].id == sourceId ) {
121 - return this.sources[i];
122 - }
123 - }
124 - return null;
125 - },
126 -
127 - /**
128 - * Selects a particular source for playback updating the "selectedSource"
129 - *
130 - * @param {Number}
131 - * index Index of source element to set as selectedSource
132 - */
133 - setSourceByIndex: function( index ) {
134 - mw.log( 'EmbedPlayer::mediaElement:selectSource:' + index );
135 - var oldSrc = this.selectedSource.getSrc()
136 - var playableSources = this.getPlayableSources();
137 - for ( var i = 0; i < playableSources.length; i++ ) {
138 - if ( i == index ) {
139 - this.selectedSource = playableSources[i];
140 - break;
141 - }
142 - }
143 - if( oldSrc != this.selectedSource.getSrc() ){
144 - $( '#' + this.parentEmbedId ).trigger( 'SourceChange');
145 - }
146 - },
147 - /**
148 - * Sets a the selected source to passed in source object
149 - * @param {Object} Source
150 - */
151 - setSource: function( source ){
152 - var oldSrc = this.selectedSource.getSrc();
153 - this.selectedSource = source;
154 - if( oldSrc != this.selectedSource.getSrc() ){
155 - $( '#' + this.parentEmbedId ).trigger( 'SourceChange');
156 - }
157 - },
158 -
159 -
160 - /**
161 - * Selects the default source via cookie preference, default marked, or by
162 - * id order
163 - */
164 - autoSelectSource: function() {
165 - mw.log( 'EmbedPlayer::mediaElement::autoSelectSource' );
166 - var _this = this;
167 - // Select the default source
168 - var playableSources = this.getPlayableSources();
169 - var flash_flag = ogg_flag = false;
170 -
171 - // Check if there are any playableSources
172 - if( playableSources.length == 0 ){
173 - return false;
174 - }
175 - var setSelectedSource = function( source ){
176 - _this.selectedSource = source;
177 - };
178 -
179 - // Set via user-preference
180 - $.each( playableSources, function( inx, source ){
181 - var mimeType =source.mimeType;
182 - if ( mw.EmbedTypes.getMediaPlayers().preference[ 'format_preference' ] == mimeType ) {
183 - mw.log( 'MediaElement::autoSelectSource: Set via preference: ' + source.mimeType );
184 - setSelectedSource( source );
185 - return true;
186 - }
187 - });
188 -
189 - // Set via module driven preference:
190 - $(this).trigger( 'AutoSelectSource', [ playableSources ] );
191 - if( _this.selectedSource ){
192 - mw.log('MediaElement::autoSelectSource: Set via trigger::' );
193 - return true;
194 - }
195 -
196 - // Set via marked default:
197 - $.each( playableSources, function( inx, source ){
198 - if ( source.markedDefault ) {
199 - mw.log( 'MediaElement::autoSelectSource: Set via marked default: ' + source.markedDefault );
200 - setSelectedSource( source );
201 - return true;
202 - }
203 - });
204 -
205 - //Set via user bandwith pref
206 - if( $.cookie('EmbedPlayer.UserBandwidth') ){
207 - $.each( playableSources, function(inx, source ){
208 - if( source.bandwidth ){
209 - if( source.bandwidth < $.cookie('EmbedPlayer.UserBandwidth') ){
210 - setSelectedSource( source );
211 - }
212 - }
213 - });
214 - }
215 - if ( this.selectedSource ) {
216 - mw.log('MediaElement::autoSelectSource: Set via bandwidth prefrence: source ' + source.bandwidth + ' user: ' + $.cookie('EmbedPlayer.UserBandwidth') );
217 - return true;
218 - }
219 -
220 - // Set via embed resolution closest to relative to display size
221 - var minSizeDelta = null;
222 - var displayWidth = $('#' + this.parentEmbedId).width();
223 - $.each( playableSources, function(inx, source ){
224 - if( source.width && displayWidth ){
225 - var sizeDelta = Math.abs( source.width - displayWidth );
226 - mw.log('MediaElement::autoSelectSource: size delta : ' + sizeDelta + ' for s:' + source.width );
227 - if( minSizeDelta == null || sizeDelta < minSizeDelta){
228 - minSizeDelta = sizeDelta;
229 - setSelectedSource( source );
230 - }
231 - }
232 - });
233 -
234 - // If we found a source via display resolution return true
235 - if ( this.selectedSource ) {
236 - mw.log('MediaElement::autoSelectSource: Set via embed resolution:' + this.selectedSource.width + ' close to: ' + displayWidth );
237 - return true;
238 - }
239 -
240 -
241 - // Prefer native playback ( and prefer WebM over ogg and h.264 )
242 - var namedSources = [];
243 - $.each( playableSources, function(inx, source ){
244 - var mimeType = source.mimeType;
245 - var player = mw.EmbedTypes.getMediaPlayers().defaultPlayer( mimeType );
246 - if ( player && player.library == 'Native' ) {
247 - switch( player.id ){
248 - case 'oggNative':
249 - namedSources['ogg'] = source;
250 - break;
251 - case 'webmNative':
252 - namedSources['webm'] = source;
253 - break;
254 - case 'h264Native':
255 - namedSources['h264'] = source;
256 - break;
257 - }
258 - }
259 - });
260 - var codecPref =mw.getConfig( 'EmbedPlayer.CodecPreference');
261 - for(var i =0; i < codecPref.length; i++){
262 - var codec = codecPref[ i ];
263 - if( namedSources[ codec ]){
264 - setSelectedSource( namedSources[ codec ] );
265 - return true;
266 - }
267 - };
268 -
269 -
270 - // Set h264 via native or flash fallback
271 - $.each( playableSources, function(inx, source ){
272 - var mimeType =source.mimeType;
273 - var player = mw.EmbedTypes.getMediaPlayers().defaultPlayer( mimeType );
274 - if ( mimeType == 'video/h264'
275 - && player
276 - && (
277 - player.library == 'Native'
278 - ||
279 - player.library == 'Kplayer'
280 - )
281 - ) {
282 - mw.log('MediaElement::autoSelectSource: Set h264 via native or flash fallback');
283 - setSelectedSource( source );
284 - return true;
285 - }
286 - });
287 -
288 - // Else just select first source
289 - if ( !this.selectedSource ) {
290 - mw.log( 'MediaElement::autoSelectSource: Set via first source:' + playableSources[0] );
291 - setSelectedSource( playableSources[0] );
292 - return true;
293 - }
294 - // No Source found so no source selected
295 - return false;
296 - },
297 -
298 - /**
299 - * check if the mime is ogg
300 - */
301 - isOgg: function( mimeType ){
302 - if ( mimeType == 'video/ogg'
303 - || mimeType == 'ogg/video'
304 - || mimeType == 'video/annodex'
305 - || mimeType == 'application/ogg'
306 - ) {
307 - return true;
308 - }
309 - return false;
310 - },
311 -
312 - /**
313 - * Returns the thumbnail URL for the media element.
314 - *
315 - * @returns {String} thumbnail URL
316 - */
317 - getPosterSrc: function( ) {
318 - return this.poster;
319 - },
320 -
321 - /**
322 - * Checks whether there is a stream of a specified MIME type.
323 - *
324 - * @param {String}
325 - * mimeType MIME type to check.
326 - * @return {Boolean} true if sources include MIME false if not.
327 - */
328 - hasStreamOfMIMEType: function( mimeType )
329 - {
330 - for ( var i = 0; i < this.sources.length; i++ )
331 - {
332 - if ( this.sources[i].getMIMEType() == mimeType ){
333 - return true;
334 - }
335 - }
336 - return false;
337 - },
338 -
339 - /**
340 - * Checks if media is a playable type
341 - */
342 - isPlayableType: function( mimeType ) {
343 - if ( mw.EmbedTypes.getMediaPlayers().defaultPlayer( mimeType ) ) {
344 - return true;
345 - } else {
346 - return false;
347 - }
348 - },
349 -
350 - /**
351 - * Adds a single mediaSource using the provided element if the element has a
352 - * 'src' attribute.
353 - *
354 - * @param {Element}
355 - * element <video>, <source> or <mediaSource> <text> element.
356 - */
357 - tryAddSource: function( element ) {
358 - // mw.log( 'f:tryAddSource:' + $( element ).attr( "src" ) );
359 - var newSrc = $( element ).attr( 'src' );
360 - if ( newSrc ) {
361 - // make sure an existing element with the same src does not already
362 - // exist:
363 - for ( var i = 0; i < this.sources.length; i++ ) {
364 - if ( this.sources[i].src == newSrc ) {
365 - // Source already exists update any new attr:
366 - this.sources[i].updateSource( element );
367 - return this.sources[i];
368 - }
369 - }
370 - }
371 - // Create a new source
372 - var source = new mediaSource( element );
373 -
374 - this.sources.push( source );
375 - // mw.log( 'tryAddSource: added source ::' + source + 'sl:' +
376 - // this.sources.length );
377 - return source;
378 - },
379 -
380 - /**
381 - * Get playable sources
382 - *
383 - * @returns {Array} of playable media sources
384 - */
385 - getPlayableSources: function() {
386 - var playableSources = [];
387 - for ( var i = 0; i < this.sources.length; i++ ) {
388 - if ( this.isPlayableType( this.sources[i].mimeType ) ) {
389 - playableSources.push( this.sources[i] );
390 - }
391 - };
392 - return playableSources;
393 - }
394 -};
395 -
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/MediaPlayer.js
@@ -1,102 +0,0 @@
2 -/**
3 - * mediaPlayer represents a media player plugin.
4 - *
5 - * @param {String}
6 - * id id used for the plugin.
7 - * @param {Array}
8 - * supported_types an array of supported MIME types.
9 - * @param {String}
10 - * library external script containing the plugin interface code.
11 - * @constructor
12 - */
13 -
14 -
15 -function mediaPlayer( id, supported_types, library )
16 -{
17 - this.id = id;
18 - this.supported_types = supported_types;
19 - this.library = library;
20 - this.loaded = false;
21 - this.loading_callbacks = new Array();
22 - return this;
23 -}
24 -mediaPlayer.prototype = {
25 - // Id of the mediaPlayer
26 - id:null,
27 -
28 - // Mime types supported by this player
29 - supported_types:null,
30 -
31 - // Player library ie: native, vlc, java etc.
32 - library:null,
33 -
34 - // Flag stores the mediaPlayer load state
35 - loaded:false,
36 -
37 - /**
38 - * Checks support for a given MIME type
39 - *
40 - * @param {String}
41 - * type Mime type to check against supported_types
42 - * @return {Boolean} true if mime type is supported false if mime type is
43 - * unsupported
44 - */
45 - supportsMIMEType: function( type ) {
46 - for ( var i = 0; i < this.supported_types.length; i++ ) {
47 - if ( this.supported_types[i] == type )
48 - return true;
49 - }
50 - return false;
51 - },
52 -
53 - /**
54 - * Get the "name" of the player from a predictable msg key
55 - */
56 - getName: function() {
57 - return gM( 'mwe-embedplayer-ogg-player-' + this.id );
58 - },
59 -
60 - /**
61 - * Loads the player library & player skin config ( if needed ) and then
62 - * calls the callback.
63 - *
64 - * @param {Function}
65 - * callback Function to be called once player library is loaded.
66 - */
67 - load: function( callback ) {
68 - // Load player library ( upper case the first letter of the library )
69 - mw.load( [
70 - 'mw.EmbedPlayer' + this.library.substr(0,1).toUpperCase() + this.library.substr(1)
71 - ], function() {
72 - if( callback ){
73 - callback();
74 - }
75 - } );
76 - }
77 -};
78 -
79 -/**
80 - * players and supported mime types In an ideal world we would query the plugin
81 - * to get what mime types it supports in practice not always reliable/available
82 - *
83 - * We can't cleanly store these values per library since player library is sometimes
84 - * loaded post player detection
85 - */
86 -
87 -// Flash based players:
88 -var kplayer = new mediaPlayer('kplayer', ['video/x-flv', 'video/h264'], 'Kplayer');
89 -
90 -// Java based player
91 -var cortadoPlayer = new mediaPlayer( 'cortado', ['video/ogg', 'audio/ogg', 'application/ogg'], 'Java' );
92 -
93 -// Native html5 players
94 -var oggNativePlayer = new mediaPlayer( 'oggNative', ['video/ogg', 'audio/ogg', 'application/ogg' ], 'Native' );
95 -var h264NativePlayer = new mediaPlayer( 'h264Native', ['video/h264'], 'Native' );
96 -var webmNativePlayer = new mediaPlayer( 'webmNative', ['video/webm'], 'Native' );
97 -
98 -// VLC player
99 -var vlcMineList = ['video/ogg', 'audio/ogg', 'application/ogg', 'video/x-flv', 'video/mp4', 'video/h264', 'video/x-msvideo', 'video/mpeg'];
100 -var vlcPlayer = new mediaPlayer( 'vlc-player', vlcMineList, 'Vlc' );
101 -
102 -// Generic plugin
103 -var oggPluginPlayer = new mediaPlayer( 'oggPlugin', ['video/ogg', 'application/ogg'], 'Generic' );
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/MediaPlayers.js
@@ -1,184 +0,0 @@
2 -/**
3 - * mediaPlayers is a collection of mediaPlayer objects supported by the client.
4 - *
5 - * @constructor
6 - */
7 -
8 -function mediaPlayers()
9 -{
10 - this.init();
11 -}
12 -
13 -mediaPlayers.prototype =
14 -{
15 - // The list of players supported
16 - players : null,
17 -
18 - // Store per mime-type prefrences for players
19 - preference : { },
20 -
21 - // Stores the default set of players for a given mime type
22 - defaultPlayers : { },
23 -
24 - /**
25 - * Initializartion function sets the default order for players for a given
26 - * mime type
27 - */
28 - init: function() {
29 - this.players = new Array();
30 - this.loadPreferences();
31 -
32 - // set up default players order for each library type
33 - this.defaultPlayers['video/x-flv'] = ['Kplayer', 'Vlc'];
34 - this.defaultPlayers['video/h264'] = ['Native', 'Kplayer', 'Vlc'];
35 -
36 - this.defaultPlayers['video/ogg'] = ['Native', 'Vlc', 'Java', 'Generic'];
37 - this.defaultPlayers['video/webm'] = ['Native', 'Vlc'];
38 - this.defaultPlayers['application/ogg'] = ['Native', 'Vlc', 'Java', 'Generic'];
39 - this.defaultPlayers['audio/ogg'] = ['Native', 'Vlc', 'Java' ];
40 - this.defaultPlayers['video/mp4'] = ['Vlc'];
41 - this.defaultPlayers['video/mpeg'] = ['Vlc'];
42 - this.defaultPlayers['video/x-msvideo'] = ['Vlc'];
43 -
44 - this.defaultPlayers['text/html'] = ['Html'];
45 - this.defaultPlayers['image/jpeg'] = ['Html'];
46 - this.defaultPlayers['image/png'] = ['Html'];
47 - this.defaultPlayers['image/svg'] = ['Html'];
48 -
49 - },
50 -
51 - /**
52 - * Adds a Player to the player list
53 - *
54 - * @param {Object}
55 - * player Player object to be added
56 - */
57 - addPlayer: function( player ) {
58 - for ( var i = 0; i < this.players.length; i++ ) {
59 - if ( this.players[i].id == player.id ) {
60 - // Player already found
61 - return ;
62 - }
63 - }
64 -
65 -
66 - // Add the player:
67 - this.players.push( player );
68 - },
69 -
70 - /**
71 - * Checks if a player is supported by id
72 - */
73 - isSupportedPlayer: function( playerId ){
74 - for( var i=0; i < this.players.length; i++ ){
75 - if( this.players[i].id == playerId ){
76 - return true;
77 - }
78 - }
79 - return false;
80 - },
81 -
82 - /**
83 - * get players that support a given mimeType
84 - *
85 - * @param {String}
86 - * mimeType Mime type of player set
87 - * @return {Array} Array of players that support a the requested mime type
88 - */
89 - getMIMETypePlayers: function( mimeType ) {
90 - var mimePlayers = new Array();
91 - var _this = this;
92 - if ( this.defaultPlayers[mimeType] ) {
93 - $.each( this.defaultPlayers[ mimeType ], function( d, lib ) {
94 - var library = _this.defaultPlayers[ mimeType ][ d ];
95 - for ( var i = 0; i < _this.players.length; i++ ) {
96 - if ( _this.players[i].library == library && _this.players[i].supportsMIMEType( mimeType ) ) {
97 - mimePlayers.push( _this.players[i] );
98 - }
99 - }
100 - } );
101 - }
102 - return mimePlayers;
103 - },
104 -
105 - /**
106 - * Default player for a given mime type
107 - *
108 - * @param {String}
109 - * mimeType Mime type of the requested player
110 - * @return Player for mime type null if no player found
111 - */
112 - defaultPlayer : function( mimeType ) {
113 - // mw.log( "get defaultPlayer for " + mimeType );
114 - var mimePlayers = this.getMIMETypePlayers( mimeType );
115 - if ( mimePlayers.length > 0 )
116 - {
117 - // Check for prior preference for this mime type
118 - for ( var i = 0; i < mimePlayers.length; i++ ) {
119 - if ( mimePlayers[i].id == this.preference[mimeType] )
120 - return mimePlayers[i];
121 - }
122 - // Otherwise just return the first compatible player
123 - // (it will be chosen according to the defaultPlayers list
124 - return mimePlayers[0];
125 - }
126 - // mw.log( 'No default player found for ' + mimeType );
127 - return null;
128 - },
129 -
130 - /**
131 - * Sets the format preference.
132 - *
133 - * @param {String}
134 - * mimeFormat Prefered format
135 - */
136 - setFormatPreference : function ( mimeFormat ) {
137 - this.preference['formatPreference'] = mimeFormat;
138 - $.cookie( 'EmbedPlayer.Preference', JSON.stringify( this.preference) );
139 - },
140 -
141 - /**
142 - * Sets the player preference
143 - *
144 - * @param {String}
145 - * playerId Prefered player id
146 - * @param {String}
147 - * mimeType Mime type for the associated player stream
148 - */
149 - setPlayerPreference : function( playerId, mimeType ) {
150 - var selectedPlayer = null;
151 - for ( var i = 0; i < this.players.length; i++ ) {
152 - if ( this.players[i].id == playerId ) {
153 - selectedPlayer = this.players[i];
154 - mw.log( 'EmbedPlayer::setPlayerPreference: choosing ' + playerId + ' for ' + mimeType );
155 - this.preference[ mimeType ] = playerId;
156 - $.cookie( 'EmbedPlayer.Preference', JSON.stringify( this.preference ) );
157 - break;
158 - }
159 - }
160 - // Update All the player instances on the page
161 - if ( selectedPlayer ) {
162 - $('.mwEmbedPlayer').each(function(inx, playerTarget ){
163 - var embedPlayer = $( playerTarget ).get( 0 );
164 - if ( embedPlayer.mediaElement.selectedSource
165 - && ( embedPlayer.mediaElement.selectedSource.mimeType == mimeType ) )
166 - {
167 - embedPlayer.selectPlayer( selectedPlayer );
168 - }
169 - });
170 - }
171 - },
172 -
173 - /**
174 - * Loads the user preference settings from a cookie
175 - */
176 - loadPreferences : function ( ) {
177 - this.preference = { };
178 - // See if we have a cookie set to a clientSupported type:
179 - if( $.cookie( 'EmbedPlayer.Preference' ) ) {
180 - this.preference = JSON.parse( $.cookie( 'EmbedPlayer.Preference' ) );
181 - }
182 - }
183 -};
184 -
185 -
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/MediaSource.js
@@ -1,370 +0,0 @@
2 -/**
3 - * mediaSource class represents a source for a media element.
4 - *
5 - * @param {Element}
6 - * element: MIME type of the source.
7 - * @constructor
8 - */
9 -
10 -/**
11 - * The base source attribute checks also see:
12 - * http://dev.w3.org/html5/spec/Overview.html#the-source-element
13 - */
14 -mw.mergeConfig( 'EmbedPlayer.SourceAttributes', [
15 - // source id
16 - 'id',
17 -
18 - // media url
19 - 'src',
20 -
21 - // Title string for the source asset
22 - 'title',
23 -
24 - // boolean if we support temporal url requests on the source media
25 - 'URLTimeEncoding',
26 -
27 - /* data- attributes ( not yet standards )
28 - * NOTE data- is striped from the attribute once added to the MediaSrouce object
29 - */
30 -
31 - // Media has a startOffset ( used for plugins that
32 - // display ogg page time rather than presentation time
33 - 'data-startoffset',
34 -
35 - // A hint to the duration of the media file so that duration
36 - // can be displayed in the player without loading the media file
37 - 'data-durationhint',
38 -
39 - // Source stream qualities ( will eventually be adaptive streaming )
40 - 'data-shorttitle', // short title for stream ( useful for stream switching control bar widget)
41 - 'data-width', // the width of the stream
42 - 'data-height', // the height of the stream
43 - 'data-bandwidth', // the overall bitrate of the stream
44 - 'data-framerate', // the framereate of the stream
45 -
46 - // Media start time
47 - 'start',
48 -
49 - // Media end time
50 - 'end',
51 -
52 - // If the source is the default source
53 - 'default'
54 -] );
55 -function mediaSource( element ) {
56 - this.init( element );
57 -}
58 -
59 -mediaSource.prototype = {
60 - // True if the source has been marked as the default.
61 - markedDefault: false,
62 -
63 - // True if the source supports url specification of offset and duration
64 - URLTimeEncoding:false,
65 -
66 - // Start offset of the requested segment
67 - startOffset: 0,
68 -
69 - // Duration of the requested segment (0 if not known)
70 - duration:0,
71 -
72 - /**
73 - * MediaSource constructor:
74 - */
75 - init : function( element ) {
76 - // mw.log('EmbedPlayer::adding mediaSource: ' + element);
77 - this.src = $( element ).attr( 'src' );
78 -
79 - // Set default URLTimeEncoding if we have a time url:
80 - // not ideal way to discover if content is on an oggz_chop server.
81 - // should check some other way.
82 - var pUrl = new mw.Uri ( this.src );
83 - if ( typeof pUrl.query[ 't' ] != 'undefined' ) {
84 - this.URLTimeEncoding = true;
85 - }
86 -
87 - var sourceAttr = mw.getConfig( 'EmbedPlayer.SourceAttributes' );
88 - for ( var i = 0; i < sourceAttr.length; i++ ) { // array loop:
89 - var attr = sourceAttr[ i ];
90 - var attrValue = $( element ).attr( attr );
91 - if ( attrValue ) {
92 - // strip data- from the attribute name
93 - if( attr.indexOf('data-') === 0){
94 - attr = attr.substr(5);
95 - }
96 - this[ attr ] = attrValue;
97 - }
98 - }
99 -
100 - // Set the content type:
101 - if ( $( element ).attr( 'type' ) ) {
102 - this.mimeType = $( element ).attr( 'type' );
103 - }else if ( $( element ).attr( 'content-type' ) ) {
104 - this.mimeType = $( element ).attr( 'content-type' );
105 - }else if( $( element ).get(0).tagName.toLowerCase() == 'audio' ){
106 - // If the element is an "audio" tag set audio format
107 - this.mimeType = 'audio/ogg';
108 - } else {
109 - this.mimeType = this.detectType( this.src );
110 - }
111 -
112 - // Conform the mime type to ogg
113 - if( this.mimeType == 'video/theora') {
114 - this.mimeType = 'video/ogg';
115 - }
116 -
117 - if( this.mimeType == 'audio/vorbis') {
118 - this.mimeType = 'audio/ogg';
119 - }
120 -
121 - // Check for parent elements ( supplies categories in "track" )
122 - if( $( element ).parent().attr('category') ) {
123 - this.category = $( element ).parent().attr('category');
124 - }
125 -
126 - if( $( element ).attr( 'default' ) ){
127 - this.markedDefault = true;
128 - }
129 -
130 - // Get the url duration ( if applicable )
131 - this.getURLDuration();
132 - },
133 -
134 - /**
135 - * Update Source title via Element
136 - *
137 - * @param {Element}
138 - * element Source element to update attributes from
139 - */
140 - updateSource: function( element ) {
141 - // for now just update the title:
142 - if ( $( element ).attr( "title" ) ) {
143 - this.title = $( element ).attr( "title" );
144 - }
145 - },
146 -
147 - /**
148 - * Updates the src time and start & end
149 - *
150 - * @param {String}
151 - * start_time: in NPT format
152 - * @param {String}
153 - * end_time: in NPT format
154 - */
155 - updateSrcTime: function ( start_npt, end_npt ) {
156 - // mw.log("f:updateSrcTime: "+ start_npt+'/'+ end_npt + ' from org: ' +
157 - // this.start_npt+ '/'+this.end_npt);
158 - // mw.log("pre uri:" + this.src);
159 - // if we have time we can use:
160 - if ( this.URLTimeEncoding ) {
161 - // make sure its a valid start time / end time (else set default)
162 - if ( !mw.npt2seconds( start_npt ) ) {
163 - start_npt = this.start_npt;
164 - }
165 -
166 - if ( !mw.npt2seconds( end_npt ) ) {
167 - end_npt = this.end_npt;
168 - }
169 -
170 - this.src = mw.replaceUrlParams( this.src, {
171 - 't': start_npt + '/' + end_npt
172 - });
173 -
174 - // update the duration
175 - this.getURLDuration();
176 - }
177 - },
178 -
179 - /**
180 - * Sets the duration and sets the end time if unset
181 - *
182 - * @param {Float}
183 - * duration: in seconds
184 - */
185 - setDuration: function ( duration ) {
186 - this.duration = duration;
187 - if ( !this.end_npt ) {
188 - this.end_npt = mw.seconds2npt( this.startOffset + duration );
189 - }
190 - },
191 -
192 - /**
193 - * MIME type accessors function.
194 - *
195 - * @return {String} the MIME type of the source.
196 - */
197 - getMIMEType: function() {
198 - if( this.mimeType ) {
199 - return this.mimeType;
200 - }
201 - this.mimeType = this.detectType( this.src );
202 - return this.mimeType;
203 - },
204 -
205 - /**
206 - * URI function.
207 - *
208 - * @param {Number}
209 - * serverSeekTime Int: Used to adjust the URI for url based
210 - * seeks)
211 - * @return {String} the URI of the source.
212 - */
213 - getSrc: function( serverSeekTime ) {
214 - if ( !serverSeekTime || !this.URLTimeEncoding ) {
215 - return this.src;
216 - }
217 - var endvar = '';
218 - if ( this.end_npt ) {
219 - endvar = '/' + this.end_npt;
220 - }
221 - return mw.replaceUrlParams( this.src,
222 - {
223 - 't': mw.seconds2npt( serverSeekTime ) + endvar
224 - }
225 - );
226 - },
227 -
228 - /**
229 - * Title accessor function.
230 - *
231 - * @return {String} Title of the source.
232 - */
233 - getTitle : function() {
234 - if( this.title ){
235 - return this.title;
236 - }
237 - // Text tracks use "label" instead of "title"
238 - if( this.label ){
239 - return this.label;
240 - }
241 -
242 - // Return a Title based on mime type:
243 - switch( this.getMIMEType() ) {
244 - case 'video/h264' :
245 - return gM( 'mwe-embedplayer-video-h264' );
246 - break;
247 - case 'video/x-flv' :
248 - return gM( 'mwe-embedplayer-video-flv' );
249 - break;
250 - case 'video/webm' :
251 - return gM( 'mwe-embedplayer-video-webm');
252 - break;
253 - case 'video/ogg' :
254 - return gM( 'mwe-embedplayer-video-ogg' );
255 - break;
256 - case 'audio/ogg' :
257 - return gM( 'mwe-embedplayer-video-audio' );
258 - break;
259 - case 'video/mpeg' :
260 - return 'MPEG video'; // FIXME: i18n
261 - break;
262 - case 'video/x-msvideo' :
263 - return 'AVI video'; // FIXME: i18n
264 - break;
265 - }
266 -
267 - // Return title based on file name:
268 - try{
269 - var fileName = new mw.Uri( this.getSrc() ).path.split('/').pop();
270 - if( fileName ){
271 - return fileName;
272 - }
273 - } catch(e){}
274 -
275 - // Return the mime type string if not known type.
276 - return this.mimeType;
277 - },
278 -
279 - /**
280 - *
281 - * Get Duration of the media in milliseconds from the source url.
282 - *
283 - * Supports media_url?t=ntp_start/ntp_end url request format
284 - */
285 - getURLDuration : function() {
286 - // check if we have a URLTimeEncoding:
287 - if ( this.URLTimeEncoding ) {
288 - var annoURL = new mw.Uri( this.src );
289 - if ( annoURL.query.t ) {
290 - var times = annoURL.query.t.split( '/' );
291 - this.start_npt = times[0];
292 - this.end_npt = times[1];
293 - this.startOffset = mw.npt2seconds( this.start_npt );
294 - this.duration = mw.npt2seconds( this.end_npt ) - this.startOffset;
295 - } else {
296 - // look for this info as attributes
297 - if ( this.startOffset ) {
298 - this.start_npt = mw.seconds2npt( this.startOffset );
299 - }
300 - if ( this.duration ) {
301 - this.end_npt = mw.seconds2npt( parseInt( this.duration ) + parseInt( this.startOffset ) );
302 - }
303 - }
304 - }
305 - },
306 -
307 - /**
308 - * Attempts to detect the type of a media file based on the URI.
309 - *
310 - * @param {String}
311 - * uri URI of the media file.
312 - * @return {String} The guessed MIME type of the file.
313 - */
314 - detectType: function( uri ) {
315 - // NOTE: if media is on the same server as the javascript
316 - // we can issue a HEAD request and read the mime type of the media...
317 - // ( this will detect media mime type independently of the url name )
318 - // http://www.jibbering.com/2002/4/httprequest.html
319 - var ext ='';
320 - try{
321 - ext = /[^.]+$/.exec( new mw.Uri( uri ).path );
322 - } catch ( e){
323 - ext = /[^.]+$/.exec( uri );
324 - };
325 -
326 - // Get the extension from the url or from the relative name:
327 - switch( ext.toString().toLowerCase() ) {
328 - case 'smil':
329 - case 'sml':
330 - return 'application/smil';
331 - break;
332 - case 'm4v':
333 - case 'mp4':
334 - return 'video/h264';
335 - break;
336 - case 'webm':
337 - return 'video/webm';
338 - break;
339 - case 'srt':
340 - return 'text/x-srt';
341 - break;
342 - case 'flv':
343 - return 'video/x-flv';
344 - break;
345 - case 'ogg':
346 - case 'ogv':
347 - return 'video/ogg';
348 - break;
349 - case 'oga':
350 - return 'audio/ogg';
351 - break;
352 - case 'anx':
353 - return 'video/ogg';
354 - break;
355 - case 'xml':
356 - return 'text/xml';
357 - break;
358 - case 'avi':
359 - return 'video/x-msvideo';
360 - break;
361 - case 'mpg':
362 - return 'video/mpeg';
363 - break;
364 - case 'mpeg':
365 - return 'video/mpeg';
366 - break;
367 - }
368 - mw.log( "Error: could not detect type of media src: " + uri );
369 - }
370 -};
371 -
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayer.js
@@ -608,7 +608,7 @@
609609 this.user_missing_plugin_html = element.innerHTML;
610610 }
611611 // Add the mediaElement object with the elements sources:
612 - this.mediaElement = new mediaElement( element );
 612+ this.mediaElement = new mw.MediaElement( element );
613613 },
614614 /**
615615 * Stop events from Propagation and blocks interface updates and trigger events.
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
@@ -0,0 +1,398 @@
 2+/**
 3+ * A media element corresponding to a <video> element.
 4+ *
 5+ * It is implemented as a collection of mediaSource objects. The media sources
 6+ * will be initialized from the <video> element, its child <source> elements,
 7+ * and/or the ROE file referenced by the <video> element.
 8+ *
 9+ * @param {element}
 10+ * videoElement <video> element used for initialization.
 11+ * @constructor
 12+ */
 13+( function( mw, $ ) {
 14+
 15+mw.MediaElement = function( element ) {
 16+ this.init( element );
 17+}
 18+
 19+mw.MediaElement.prototype = {
 20+
 21+ // The array of mediaSource elements.
 22+ sources: null,
 23+
 24+ // flag for ROE data being added.
 25+ addedROEData: false,
 26+
 27+ // Selected mediaSource element.
 28+ selectedSource: null,
 29+
 30+ /**
 31+ * Media Element constructor
 32+ *
 33+ * Sets up a mediaElement from a provided top level "video" element adds any
 34+ * child sources that are found
 35+ *
 36+ * @param {Element}
 37+ * videoElement Element that has src attribute or has children
 38+ * source elements
 39+ */
 40+ init: function( videoElement ) {
 41+ var _this = this;
 42+ mw.log( "EmbedPlayer::mediaElement:init:" + videoElement.id );
 43+ this.parentEmbedId = videoElement.id;
 44+ this.sources = new Array();
 45+
 46+ // Process the videoElement as a source element:
 47+ if ( $( videoElement ).attr( "src" ) ) {
 48+ _this.tryAddSource( videoElement );
 49+ }
 50+
 51+ // Process elements source children
 52+ $( videoElement ).find( 'source,track' ).each( function( ) {
 53+ _this.tryAddSource( this );
 54+ } );
 55+ },
 56+
 57+ /**
 58+ * Updates the time request for all sources that have a standard time
 59+ * request argument (ie &t=start_time/end_time)
 60+ *
 61+ * @param {String}
 62+ * start_npt Start time in npt format
 63+ * @param {String}
 64+ * end_npt End time in npt format
 65+ */
 66+ updateSourceTimes: function( start_npt, end_npt ) {
 67+ var _this = this;
 68+ $.each( this.sources, function( inx, mediaSource ) {
 69+ mediaSource.updateSrcTime( start_npt, end_npt );
 70+ } );
 71+ },
 72+
 73+ /**
 74+ * Check for Timed Text tracks
 75+ *
 76+ * @return {Boolean} True if text tracks exist, false if no text tracks are
 77+ * found
 78+ */
 79+ textSourceExists: function() {
 80+ for ( var i = 0; i < this.sources.length; i++ ) {
 81+ if ( this.sources[i].mimeType == 'text/cmml' ||
 82+ this.sources[i].mimeType == 'text/x-srt' )
 83+ {
 84+ return true;
 85+ }
 86+ };
 87+ return false;
 88+ },
 89+
 90+ /**
 91+ * Returns the array of mediaSources of this element.
 92+ *
 93+ * @param {String}
 94+ * [mimeFilter] Filter criteria for set of mediaSources to return
 95+ * @return {Array} mediaSource elements.
 96+ */
 97+ getSources: function( mimeFilter ) {
 98+ if ( !mimeFilter ) {
 99+ return this.sources;
 100+ }
 101+ // Apply mime filter:
 102+ var source_set = new Array();
 103+ for ( var i = 0; i < this.sources.length ; i++ ) {
 104+ if ( this.sources[i].mimeType &&
 105+ this.sources[i].mimeType.indexOf( mimeFilter ) != -1 )
 106+ {
 107+ source_set.push( this.sources[i] );
 108+ }
 109+ }
 110+ return source_set;
 111+ },
 112+
 113+ /**
 114+ * Selects a source by id
 115+ *
 116+ * @param {String}
 117+ * source_id Id of the source to select.
 118+ * @return {MediaSource} The selected mediaSource or null if not found
 119+ */
 120+ getSourceById:function( sourceId ) {
 121+ for ( var i = 0; i < this.sources.length ; i++ ) {
 122+ if ( this.sources[i].id == sourceId ) {
 123+ return this.sources[i];
 124+ }
 125+ }
 126+ return null;
 127+ },
 128+
 129+ /**
 130+ * Selects a particular source for playback updating the "selectedSource"
 131+ *
 132+ * @param {Number}
 133+ * index Index of source element to set as selectedSource
 134+ */
 135+ setSourceByIndex: function( index ) {
 136+ mw.log( 'EmbedPlayer::mediaElement:selectSource:' + index );
 137+ var oldSrc = this.selectedSource.getSrc()
 138+ var playableSources = this.getPlayableSources();
 139+ for ( var i = 0; i < playableSources.length; i++ ) {
 140+ if ( i == index ) {
 141+ this.selectedSource = playableSources[i];
 142+ break;
 143+ }
 144+ }
 145+ if( oldSrc != this.selectedSource.getSrc() ){
 146+ $( '#' + this.parentEmbedId ).trigger( 'SourceChange');
 147+ }
 148+ },
 149+ /**
 150+ * Sets a the selected source to passed in source object
 151+ * @param {Object} Source
 152+ */
 153+ setSource: function( source ){
 154+ var oldSrc = this.selectedSource.getSrc();
 155+ this.selectedSource = source;
 156+ if( oldSrc != this.selectedSource.getSrc() ){
 157+ $( '#' + this.parentEmbedId ).trigger( 'SourceChange');
 158+ }
 159+ },
 160+
 161+
 162+ /**
 163+ * Selects the default source via cookie preference, default marked, or by
 164+ * id order
 165+ */
 166+ autoSelectSource: function() {
 167+ mw.log( 'EmbedPlayer::mediaElement::autoSelectSource' );
 168+ var _this = this;
 169+ // Select the default source
 170+ var playableSources = this.getPlayableSources();
 171+ var flash_flag = ogg_flag = false;
 172+
 173+ // Check if there are any playableSources
 174+ if( playableSources.length == 0 ){
 175+ return false;
 176+ }
 177+ var setSelectedSource = function( source ){
 178+ _this.selectedSource = source;
 179+ };
 180+
 181+ // Set via user-preference
 182+ $.each( playableSources, function( inx, source ){
 183+ var mimeType =source.mimeType;
 184+ if ( mw.EmbedTypes.getMediaPlayers().preference[ 'format_preference' ] == mimeType ) {
 185+ mw.log( 'MediaElement::autoSelectSource: Set via preference: ' + source.mimeType );
 186+ setSelectedSource( source );
 187+ return true;
 188+ }
 189+ });
 190+
 191+ // Set via module driven preference:
 192+ $(this).trigger( 'AutoSelectSource', [ playableSources ] );
 193+ if( _this.selectedSource ){
 194+ mw.log('MediaElement::autoSelectSource: Set via trigger::' );
 195+ return true;
 196+ }
 197+
 198+ // Set via marked default:
 199+ $.each( playableSources, function( inx, source ){
 200+ if ( source.markedDefault ) {
 201+ mw.log( 'MediaElement::autoSelectSource: Set via marked default: ' + source.markedDefault );
 202+ setSelectedSource( source );
 203+ return true;
 204+ }
 205+ });
 206+
 207+ //Set via user bandwith pref
 208+ if( $.cookie('EmbedPlayer.UserBandwidth') ){
 209+ $.each( playableSources, function(inx, source ){
 210+ if( source.bandwidth ){
 211+ if( source.bandwidth < $.cookie('EmbedPlayer.UserBandwidth') ){
 212+ setSelectedSource( source );
 213+ }
 214+ }
 215+ });
 216+ }
 217+ if ( this.selectedSource ) {
 218+ mw.log('MediaElement::autoSelectSource: Set via bandwidth prefrence: source ' + source.bandwidth + ' user: ' + $.cookie('EmbedPlayer.UserBandwidth') );
 219+ return true;
 220+ }
 221+
 222+ // Set via embed resolution closest to relative to display size
 223+ var minSizeDelta = null;
 224+ var displayWidth = $('#' + this.parentEmbedId).width();
 225+ $.each( playableSources, function(inx, source ){
 226+ if( source.width && displayWidth ){
 227+ var sizeDelta = Math.abs( source.width - displayWidth );
 228+ mw.log('MediaElement::autoSelectSource: size delta : ' + sizeDelta + ' for s:' + source.width );
 229+ if( minSizeDelta == null || sizeDelta < minSizeDelta){
 230+ minSizeDelta = sizeDelta;
 231+ setSelectedSource( source );
 232+ }
 233+ }
 234+ });
 235+
 236+ // If we found a source via display resolution return true
 237+ if ( this.selectedSource ) {
 238+ mw.log('MediaElement::autoSelectSource: Set via embed resolution:' + this.selectedSource.width + ' close to: ' + displayWidth );
 239+ return true;
 240+ }
 241+
 242+
 243+ // Prefer native playback ( and prefer WebM over ogg and h.264 )
 244+ var namedSources = [];
 245+ $.each( playableSources, function(inx, source ){
 246+ var mimeType = source.mimeType;
 247+ var player = mw.EmbedTypes.getMediaPlayers().defaultPlayer( mimeType );
 248+ if ( player && player.library == 'Native' ) {
 249+ switch( player.id ){
 250+ case 'oggNative':
 251+ namedSources['ogg'] = source;
 252+ break;
 253+ case 'webmNative':
 254+ namedSources['webm'] = source;
 255+ break;
 256+ case 'h264Native':
 257+ namedSources['h264'] = source;
 258+ break;
 259+ }
 260+ }
 261+ });
 262+ var codecPref =mw.getConfig( 'EmbedPlayer.CodecPreference');
 263+ for(var i =0; i < codecPref.length; i++){
 264+ var codec = codecPref[ i ];
 265+ if( namedSources[ codec ]){
 266+ setSelectedSource( namedSources[ codec ] );
 267+ return true;
 268+ }
 269+ };
 270+
 271+
 272+ // Set h264 via native or flash fallback
 273+ $.each( playableSources, function(inx, source ){
 274+ var mimeType =source.mimeType;
 275+ var player = mw.EmbedTypes.getMediaPlayers().defaultPlayer( mimeType );
 276+ if ( mimeType == 'video/h264'
 277+ && player
 278+ && (
 279+ player.library == 'Native'
 280+ ||
 281+ player.library == 'Kplayer'
 282+ )
 283+ ) {
 284+ mw.log('MediaElement::autoSelectSource: Set h264 via native or flash fallback');
 285+ setSelectedSource( source );
 286+ return true;
 287+ }
 288+ });
 289+
 290+ // Else just select first source
 291+ if ( !this.selectedSource ) {
 292+ mw.log( 'MediaElement::autoSelectSource: Set via first source:' + playableSources[0] );
 293+ setSelectedSource( playableSources[0] );
 294+ return true;
 295+ }
 296+ // No Source found so no source selected
 297+ return false;
 298+ },
 299+
 300+ /**
 301+ * check if the mime is ogg
 302+ */
 303+ isOgg: function( mimeType ){
 304+ if ( mimeType == 'video/ogg'
 305+ || mimeType == 'ogg/video'
 306+ || mimeType == 'video/annodex'
 307+ || mimeType == 'application/ogg'
 308+ ) {
 309+ return true;
 310+ }
 311+ return false;
 312+ },
 313+
 314+ /**
 315+ * Returns the thumbnail URL for the media element.
 316+ *
 317+ * @returns {String} thumbnail URL
 318+ */
 319+ getPosterSrc: function( ) {
 320+ return this.poster;
 321+ },
 322+
 323+ /**
 324+ * Checks whether there is a stream of a specified MIME type.
 325+ *
 326+ * @param {String}
 327+ * mimeType MIME type to check.
 328+ * @return {Boolean} true if sources include MIME false if not.
 329+ */
 330+ hasStreamOfMIMEType: function( mimeType )
 331+ {
 332+ for ( var i = 0; i < this.sources.length; i++ )
 333+ {
 334+ if ( this.sources[i].getMIMEType() == mimeType ){
 335+ return true;
 336+ }
 337+ }
 338+ return false;
 339+ },
 340+
 341+ /**
 342+ * Checks if media is a playable type
 343+ */
 344+ isPlayableType: function( mimeType ) {
 345+ if ( mw.EmbedTypes.getMediaPlayers().defaultPlayer( mimeType ) ) {
 346+ return true;
 347+ } else {
 348+ return false;
 349+ }
 350+ },
 351+
 352+ /**
 353+ * Adds a single mediaSource using the provided element if the element has a
 354+ * 'src' attribute.
 355+ *
 356+ * @param {Element}
 357+ * element <video>, <source> or <mediaSource> <text> element.
 358+ */
 359+ tryAddSource: function( element ) {
 360+ // mw.log( 'f:tryAddSource:' + $( element ).attr( "src" ) );
 361+ var newSrc = $( element ).attr( 'src' );
 362+ if ( newSrc ) {
 363+ // make sure an existing element with the same src does not already
 364+ // exist:
 365+ for ( var i = 0; i < this.sources.length; i++ ) {
 366+ if ( this.sources[i].src == newSrc ) {
 367+ // Source already exists update any new attr:
 368+ this.sources[i].updateSource( element );
 369+ return this.sources[i];
 370+ }
 371+ }
 372+ }
 373+ // Create a new source
 374+ var source = new mw.MediaSource( element );
 375+
 376+ this.sources.push( source );
 377+ // mw.log( 'tryAddSource: added source ::' + source + 'sl:' +
 378+ // this.sources.length );
 379+ return source;
 380+ },
 381+
 382+ /**
 383+ * Get playable sources
 384+ *
 385+ * @returns {Array} of playable media sources
 386+ */
 387+ getPlayableSources: function() {
 388+ var playableSources = [];
 389+ for ( var i = 0; i < this.sources.length; i++ ) {
 390+ if ( this.isPlayableType( this.sources[i].mimeType ) ) {
 391+ playableSources.push( this.sources[i] );
 392+ }
 393+ };
 394+ return playableSources;
 395+ }
 396+};
 397+
 398+} )( mediaWiki, jQuery );
 399+
Property changes on: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
___________________________________________________________________
Added: svn:eol-style
1400 + native
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaPlayer.js
@@ -0,0 +1,78 @@
 2+/**
 3+ * mediaPlayer represents a media player plugin.
 4+ *
 5+ * @param {String}
 6+ * id id used for the plugin.
 7+ * @param {Array}
 8+ * supported_types an array of supported MIME types.
 9+ * @param {String}
 10+ * library external script containing the plugin interface code.
 11+ * @constructor
 12+ */
 13+
 14+( function( mw, $ ) {
 15+
 16+mw.MediaPlayer = function( id, supported_types, library )
 17+{
 18+ this.id = id;
 19+ this.supported_types = supported_types;
 20+ this.library = library;
 21+ this.loaded = false;
 22+ this.loading_callbacks = new Array();
 23+ return this;
 24+}
 25+mw.MediaPlayer.prototype = {
 26+ // Id of the mediaPlayer
 27+ id:null,
 28+
 29+ // Mime types supported by this player
 30+ supported_types:null,
 31+
 32+ // Player library ie: native, vlc, java etc.
 33+ library:null,
 34+
 35+ // Flag stores the mediaPlayer load state
 36+ loaded:false,
 37+
 38+ /**
 39+ * Checks support for a given MIME type
 40+ *
 41+ * @param {String}
 42+ * type Mime type to check against supported_types
 43+ * @return {Boolean} true if mime type is supported false if mime type is
 44+ * unsupported
 45+ */
 46+ supportsMIMEType: function( type ) {
 47+ for ( var i = 0; i < this.supported_types.length; i++ ) {
 48+ if ( this.supported_types[i] == type )
 49+ return true;
 50+ }
 51+ return false;
 52+ },
 53+
 54+ /**
 55+ * Get the "name" of the player from a predictable msg key
 56+ */
 57+ getName: function() {
 58+ return gM( 'mwe-embedplayer-ogg-player-' + this.id );
 59+ },
 60+
 61+ /**
 62+ * Loads the player library & player skin config ( if needed ) and then
 63+ * calls the callback.
 64+ *
 65+ * @param {Function}
 66+ * callback Function to be called once player library is loaded.
 67+ */
 68+ load: function( callback ) {
 69+ // Load player library ( upper case the first letter of the library )
 70+ mw.load( [
 71+ 'mw.EmbedPlayer' + this.library.substr(0,1).toUpperCase() + this.library.substr(1)
 72+ ], function() {
 73+ if( callback ){
 74+ callback();
 75+ }
 76+ } );
 77+ }
 78+};
 79+} )( mediaWiki, jQuery );
\ No newline at end of file
Property changes on: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaPlayer.js
___________________________________________________________________
Added: svn:eol-style
180 + native
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaPlayers.js
@@ -0,0 +1,185 @@
 2+/**
 3+ * mediaPlayers is a collection of mediaPlayer objects supported by the client.
 4+ *
 5+ * @constructor
 6+ */
 7+
 8+( function( mw, $ ) {
 9+
 10+mw.MediaPlayers = function()
 11+{
 12+ this.init();
 13+}
 14+
 15+mw.MediaPlayers.prototype = {
 16+ // The list of players supported
 17+ players : null,
 18+
 19+ // Store per mime-type prefrences for players
 20+ preference : { },
 21+
 22+ // Stores the default set of players for a given mime type
 23+ defaultPlayers : { },
 24+
 25+ /**
 26+ * Initializartion function sets the default order for players for a given
 27+ * mime type
 28+ */
 29+ init: function() {
 30+ this.players = new Array();
 31+ this.loadPreferences();
 32+
 33+ // set up default players order for each library type
 34+ this.defaultPlayers['video/x-flv'] = ['Kplayer', 'Vlc'];
 35+ this.defaultPlayers['video/h264'] = ['Native', 'Kplayer', 'Vlc'];
 36+
 37+ this.defaultPlayers['video/ogg'] = ['Native', 'Vlc', 'Java', 'Generic'];
 38+ this.defaultPlayers['video/webm'] = ['Native', 'Vlc'];
 39+ this.defaultPlayers['application/ogg'] = ['Native', 'Vlc', 'Java', 'Generic'];
 40+ this.defaultPlayers['audio/ogg'] = ['Native', 'Vlc', 'Java' ];
 41+ this.defaultPlayers['video/mp4'] = ['Vlc'];
 42+ this.defaultPlayers['video/mpeg'] = ['Vlc'];
 43+ this.defaultPlayers['video/x-msvideo'] = ['Vlc'];
 44+
 45+ this.defaultPlayers['text/html'] = ['Html'];
 46+ this.defaultPlayers['image/jpeg'] = ['Html'];
 47+ this.defaultPlayers['image/png'] = ['Html'];
 48+ this.defaultPlayers['image/svg'] = ['Html'];
 49+
 50+ },
 51+
 52+ /**
 53+ * Adds a Player to the player list
 54+ *
 55+ * @param {Object}
 56+ * player Player object to be added
 57+ */
 58+ addPlayer: function( player ) {
 59+ for ( var i = 0; i < this.players.length; i++ ) {
 60+ if ( this.players[i].id == player.id ) {
 61+ // Player already found
 62+ return ;
 63+ }
 64+ }
 65+
 66+
 67+ // Add the player:
 68+ this.players.push( player );
 69+ },
 70+
 71+ /**
 72+ * Checks if a player is supported by id
 73+ */
 74+ isSupportedPlayer: function( playerId ){
 75+ for( var i=0; i < this.players.length; i++ ){
 76+ if( this.players[i].id == playerId ){
 77+ return true;
 78+ }
 79+ }
 80+ return false;
 81+ },
 82+
 83+ /**
 84+ * get players that support a given mimeType
 85+ *
 86+ * @param {String}
 87+ * mimeType Mime type of player set
 88+ * @return {Array} Array of players that support a the requested mime type
 89+ */
 90+ getMIMETypePlayers: function( mimeType ) {
 91+ var mimePlayers = new Array();
 92+ var _this = this;
 93+ if ( this.defaultPlayers[mimeType] ) {
 94+ $.each( this.defaultPlayers[ mimeType ], function( d, lib ) {
 95+ var library = _this.defaultPlayers[ mimeType ][ d ];
 96+ for ( var i = 0; i < _this.players.length; i++ ) {
 97+ if ( _this.players[i].library == library && _this.players[i].supportsMIMEType( mimeType ) ) {
 98+ mimePlayers.push( _this.players[i] );
 99+ }
 100+ }
 101+ } );
 102+ }
 103+ return mimePlayers;
 104+ },
 105+
 106+ /**
 107+ * Default player for a given mime type
 108+ *
 109+ * @param {String}
 110+ * mimeType Mime type of the requested player
 111+ * @return Player for mime type null if no player found
 112+ */
 113+ defaultPlayer : function( mimeType ) {
 114+ // mw.log( "get defaultPlayer for " + mimeType );
 115+ var mimePlayers = this.getMIMETypePlayers( mimeType );
 116+ if ( mimePlayers.length > 0 )
 117+ {
 118+ // Check for prior preference for this mime type
 119+ for ( var i = 0; i < mimePlayers.length; i++ ) {
 120+ if ( mimePlayers[i].id == this.preference[mimeType] )
 121+ return mimePlayers[i];
 122+ }
 123+ // Otherwise just return the first compatible player
 124+ // (it will be chosen according to the defaultPlayers list
 125+ return mimePlayers[0];
 126+ }
 127+ // mw.log( 'No default player found for ' + mimeType );
 128+ return null;
 129+ },
 130+
 131+ /**
 132+ * Sets the format preference.
 133+ *
 134+ * @param {String}
 135+ * mimeFormat Prefered format
 136+ */
 137+ setFormatPreference : function ( mimeFormat ) {
 138+ this.preference['formatPreference'] = mimeFormat;
 139+ $.cookie( 'EmbedPlayer.Preference', JSON.stringify( this.preference) );
 140+ },
 141+
 142+ /**
 143+ * Sets the player preference
 144+ *
 145+ * @param {String}
 146+ * playerId Prefered player id
 147+ * @param {String}
 148+ * mimeType Mime type for the associated player stream
 149+ */
 150+ setPlayerPreference : function( playerId, mimeType ) {
 151+ var selectedPlayer = null;
 152+ for ( var i = 0; i < this.players.length; i++ ) {
 153+ if ( this.players[i].id == playerId ) {
 154+ selectedPlayer = this.players[i];
 155+ mw.log( 'EmbedPlayer::setPlayerPreference: choosing ' + playerId + ' for ' + mimeType );
 156+ this.preference[ mimeType ] = playerId;
 157+ $.cookie( 'EmbedPlayer.Preference', JSON.stringify( this.preference ) );
 158+ break;
 159+ }
 160+ }
 161+ // Update All the player instances on the page
 162+ if ( selectedPlayer ) {
 163+ $('.mwEmbedPlayer').each(function(inx, playerTarget ){
 164+ var embedPlayer = $( playerTarget ).get( 0 );
 165+ if ( embedPlayer.mediaElement.selectedSource
 166+ && ( embedPlayer.mediaElement.selectedSource.mimeType == mimeType ) )
 167+ {
 168+ embedPlayer.selectPlayer( selectedPlayer );
 169+ }
 170+ });
 171+ }
 172+ },
 173+
 174+ /**
 175+ * Loads the user preference settings from a cookie
 176+ */
 177+ loadPreferences : function ( ) {
 178+ this.preference = { };
 179+ // See if we have a cookie set to a clientSupported type:
 180+ if( $.cookie( 'EmbedPlayer.Preference' ) ) {
 181+ this.preference = JSON.parse( $.cookie( 'EmbedPlayer.Preference' ) );
 182+ }
 183+ }
 184+};
 185+
 186+} )( mediaWiki, jQuery );
\ No newline at end of file
Property changes on: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaPlayers.js
___________________________________________________________________
Added: svn:eol-style
1187 + native
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaSource.js
@@ -0,0 +1,375 @@
 2+/**
 3+ * mediaSource class represents a source for a media element.
 4+ *
 5+ * @param {Element}
 6+ * element: MIME type of the source.
 7+ * @constructor
 8+ */
 9+
 10+/**
 11+ * The base source attribute checks also see:
 12+ * http://dev.w3.org/html5/spec/Overview.html#the-source-element
 13+ */
 14+
 15+( function( mw, $ ) {
 16+
 17+mw.mergeConfig( 'EmbedPlayer.SourceAttributes', [
 18+ // source id
 19+ 'id',
 20+
 21+ // media url
 22+ 'src',
 23+
 24+ // Title string for the source asset
 25+ 'title',
 26+
 27+ // boolean if we support temporal url requests on the source media
 28+ 'URLTimeEncoding',
 29+
 30+ /* data- attributes ( not yet standards )
 31+ * NOTE data- is striped from the attribute once added to the MediaSrouce object
 32+ */
 33+
 34+ // Media has a startOffset ( used for plugins that
 35+ // display ogg page time rather than presentation time
 36+ 'data-startoffset',
 37+
 38+ // A hint to the duration of the media file so that duration
 39+ // can be displayed in the player without loading the media file
 40+ 'data-durationhint',
 41+
 42+ // Source stream qualities ( will eventually be adaptive streaming )
 43+ 'data-shorttitle', // short title for stream ( useful for stream switching control bar widget)
 44+ 'data-width', // the width of the stream
 45+ 'data-height', // the height of the stream
 46+ 'data-bandwidth', // the overall bitrate of the stream
 47+ 'data-framerate', // the framereate of the stream
 48+
 49+ // Media start time
 50+ 'start',
 51+
 52+ // Media end time
 53+ 'end',
 54+
 55+ // If the source is the default source
 56+ 'default'
 57+] );
 58+
 59+mw.MediaSource = function( element ) {
 60+ this.init( element );
 61+}
 62+
 63+mw.MediaSource.prototype = {
 64+ // True if the source has been marked as the default.
 65+ markedDefault: false,
 66+
 67+ // True if the source supports url specification of offset and duration
 68+ URLTimeEncoding:false,
 69+
 70+ // Start offset of the requested segment
 71+ startOffset: 0,
 72+
 73+ // Duration of the requested segment (0 if not known)
 74+ duration:0,
 75+
 76+ /**
 77+ * MediaSource constructor:
 78+ */
 79+ init : function( element ) {
 80+ // mw.log('EmbedPlayer::adding mediaSource: ' + element);
 81+ this.src = $( element ).attr( 'src' );
 82+
 83+ // Set default URLTimeEncoding if we have a time url:
 84+ // not ideal way to discover if content is on an oggz_chop server.
 85+ // should check some other way.
 86+ var pUrl = new mw.Uri ( this.src );
 87+ if ( typeof pUrl.query[ 't' ] != 'undefined' ) {
 88+ this.URLTimeEncoding = true;
 89+ }
 90+
 91+ var sourceAttr = mw.getConfig( 'EmbedPlayer.SourceAttributes' );
 92+ for ( var i = 0; i < sourceAttr.length; i++ ) { // array loop:
 93+ var attr = sourceAttr[ i ];
 94+ var attrValue = $( element ).attr( attr );
 95+ if ( attrValue ) {
 96+ // strip data- from the attribute name
 97+ if( attr.indexOf('data-') === 0){
 98+ attr = attr.substr(5);
 99+ }
 100+ this[ attr ] = attrValue;
 101+ }
 102+ }
 103+
 104+ // Set the content type:
 105+ if ( $( element ).attr( 'type' ) ) {
 106+ this.mimeType = $( element ).attr( 'type' );
 107+ }else if ( $( element ).attr( 'content-type' ) ) {
 108+ this.mimeType = $( element ).attr( 'content-type' );
 109+ }else if( $( element ).get(0).tagName.toLowerCase() == 'audio' ){
 110+ // If the element is an "audio" tag set audio format
 111+ this.mimeType = 'audio/ogg';
 112+ } else {
 113+ this.mimeType = this.detectType( this.src );
 114+ }
 115+
 116+ // Conform the mime type to ogg
 117+ if( this.mimeType == 'video/theora') {
 118+ this.mimeType = 'video/ogg';
 119+ }
 120+
 121+ if( this.mimeType == 'audio/vorbis') {
 122+ this.mimeType = 'audio/ogg';
 123+ }
 124+
 125+ // Check for parent elements ( supplies categories in "track" )
 126+ if( $( element ).parent().attr('category') ) {
 127+ this.category = $( element ).parent().attr('category');
 128+ }
 129+
 130+ if( $( element ).attr( 'default' ) ){
 131+ this.markedDefault = true;
 132+ }
 133+
 134+ // Get the url duration ( if applicable )
 135+ this.getURLDuration();
 136+ },
 137+
 138+ /**
 139+ * Update Source title via Element
 140+ *
 141+ * @param {Element}
 142+ * element Source element to update attributes from
 143+ */
 144+ updateSource: function( element ) {
 145+ // for now just update the title:
 146+ if ( $( element ).attr( "title" ) ) {
 147+ this.title = $( element ).attr( "title" );
 148+ }
 149+ },
 150+
 151+ /**
 152+ * Updates the src time and start & end
 153+ *
 154+ * @param {String}
 155+ * start_time: in NPT format
 156+ * @param {String}
 157+ * end_time: in NPT format
 158+ */
 159+ updateSrcTime: function ( start_npt, end_npt ) {
 160+ // mw.log("f:updateSrcTime: "+ start_npt+'/'+ end_npt + ' from org: ' +
 161+ // this.start_npt+ '/'+this.end_npt);
 162+ // mw.log("pre uri:" + this.src);
 163+ // if we have time we can use:
 164+ if ( this.URLTimeEncoding ) {
 165+ // make sure its a valid start time / end time (else set default)
 166+ if ( !mw.npt2seconds( start_npt ) ) {
 167+ start_npt = this.start_npt;
 168+ }
 169+
 170+ if ( !mw.npt2seconds( end_npt ) ) {
 171+ end_npt = this.end_npt;
 172+ }
 173+
 174+ this.src = mw.replaceUrlParams( this.src, {
 175+ 't': start_npt + '/' + end_npt
 176+ });
 177+
 178+ // update the duration
 179+ this.getURLDuration();
 180+ }
 181+ },
 182+
 183+ /**
 184+ * Sets the duration and sets the end time if unset
 185+ *
 186+ * @param {Float}
 187+ * duration: in seconds
 188+ */
 189+ setDuration: function ( duration ) {
 190+ this.duration = duration;
 191+ if ( !this.end_npt ) {
 192+ this.end_npt = mw.seconds2npt( this.startOffset + duration );
 193+ }
 194+ },
 195+
 196+ /**
 197+ * MIME type accessors function.
 198+ *
 199+ * @return {String} the MIME type of the source.
 200+ */
 201+ getMIMEType: function() {
 202+ if( this.mimeType ) {
 203+ return this.mimeType;
 204+ }
 205+ this.mimeType = this.detectType( this.src );
 206+ return this.mimeType;
 207+ },
 208+
 209+ /**
 210+ * URI function.
 211+ *
 212+ * @param {Number}
 213+ * serverSeekTime Int: Used to adjust the URI for url based
 214+ * seeks)
 215+ * @return {String} the URI of the source.
 216+ */
 217+ getSrc: function( serverSeekTime ) {
 218+ if ( !serverSeekTime || !this.URLTimeEncoding ) {
 219+ return this.src;
 220+ }
 221+ var endvar = '';
 222+ if ( this.end_npt ) {
 223+ endvar = '/' + this.end_npt;
 224+ }
 225+ return mw.replaceUrlParams( this.src,
 226+ {
 227+ 't': mw.seconds2npt( serverSeekTime ) + endvar
 228+ }
 229+ );
 230+ },
 231+
 232+ /**
 233+ * Title accessor function.
 234+ *
 235+ * @return {String} Title of the source.
 236+ */
 237+ getTitle : function() {
 238+ if( this.title ){
 239+ return this.title;
 240+ }
 241+ // Text tracks use "label" instead of "title"
 242+ if( this.label ){
 243+ return this.label;
 244+ }
 245+
 246+ // Return a Title based on mime type:
 247+ switch( this.getMIMEType() ) {
 248+ case 'video/h264' :
 249+ return gM( 'mwe-embedplayer-video-h264' );
 250+ break;
 251+ case 'video/x-flv' :
 252+ return gM( 'mwe-embedplayer-video-flv' );
 253+ break;
 254+ case 'video/webm' :
 255+ return gM( 'mwe-embedplayer-video-webm');
 256+ break;
 257+ case 'video/ogg' :
 258+ return gM( 'mwe-embedplayer-video-ogg' );
 259+ break;
 260+ case 'audio/ogg' :
 261+ return gM( 'mwe-embedplayer-video-audio' );
 262+ break;
 263+ case 'video/mpeg' :
 264+ return 'MPEG video'; // FIXME: i18n
 265+ break;
 266+ case 'video/x-msvideo' :
 267+ return 'AVI video'; // FIXME: i18n
 268+ break;
 269+ }
 270+
 271+ // Return title based on file name:
 272+ try{
 273+ var fileName = new mw.Uri( this.getSrc() ).path.split('/').pop();
 274+ if( fileName ){
 275+ return fileName;
 276+ }
 277+ } catch(e){}
 278+
 279+ // Return the mime type string if not known type.
 280+ return this.mimeType;
 281+ },
 282+
 283+ /**
 284+ *
 285+ * Get Duration of the media in milliseconds from the source url.
 286+ *
 287+ * Supports media_url?t=ntp_start/ntp_end url request format
 288+ */
 289+ getURLDuration : function() {
 290+ // check if we have a URLTimeEncoding:
 291+ if ( this.URLTimeEncoding ) {
 292+ var annoURL = new mw.Uri( this.src );
 293+ if ( annoURL.query.t ) {
 294+ var times = annoURL.query.t.split( '/' );
 295+ this.start_npt = times[0];
 296+ this.end_npt = times[1];
 297+ this.startOffset = mw.npt2seconds( this.start_npt );
 298+ this.duration = mw.npt2seconds( this.end_npt ) - this.startOffset;
 299+ } else {
 300+ // look for this info as attributes
 301+ if ( this.startOffset ) {
 302+ this.start_npt = mw.seconds2npt( this.startOffset );
 303+ }
 304+ if ( this.duration ) {
 305+ this.end_npt = mw.seconds2npt( parseInt( this.duration ) + parseInt( this.startOffset ) );
 306+ }
 307+ }
 308+ }
 309+ },
 310+
 311+ /**
 312+ * Attempts to detect the type of a media file based on the URI.
 313+ *
 314+ * @param {String}
 315+ * uri URI of the media file.
 316+ * @return {String} The guessed MIME type of the file.
 317+ */
 318+ detectType: function( uri ) {
 319+ // NOTE: if media is on the same server as the javascript
 320+ // we can issue a HEAD request and read the mime type of the media...
 321+ // ( this will detect media mime type independently of the url name )
 322+ // http://www.jibbering.com/2002/4/httprequest.html
 323+ var ext ='';
 324+ try{
 325+ ext = /[^.]+$/.exec( new mw.Uri( uri ).path );
 326+ } catch ( e){
 327+ ext = /[^.]+$/.exec( uri );
 328+ };
 329+
 330+ // Get the extension from the url or from the relative name:
 331+ switch( ext.toString().toLowerCase() ) {
 332+ case 'smil':
 333+ case 'sml':
 334+ return 'application/smil';
 335+ break;
 336+ case 'm4v':
 337+ case 'mp4':
 338+ return 'video/h264';
 339+ break;
 340+ case 'webm':
 341+ return 'video/webm';
 342+ break;
 343+ case 'srt':
 344+ return 'text/x-srt';
 345+ break;
 346+ case 'flv':
 347+ return 'video/x-flv';
 348+ break;
 349+ case 'ogg':
 350+ case 'ogv':
 351+ return 'video/ogg';
 352+ break;
 353+ case 'oga':
 354+ return 'audio/ogg';
 355+ break;
 356+ case 'anx':
 357+ return 'video/ogg';
 358+ break;
 359+ case 'xml':
 360+ return 'text/xml';
 361+ break;
 362+ case 'avi':
 363+ return 'video/x-msvideo';
 364+ break;
 365+ case 'mpg':
 366+ return 'video/mpeg';
 367+ break;
 368+ case 'mpeg':
 369+ return 'video/mpeg';
 370+ break;
 371+ }
 372+ mw.log( "Error: could not detect type of media src: " + uri );
 373+ }
 374+};
 375+
 376+} )( mediaWiki, jQuery );
\ No newline at end of file
Property changes on: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaSource.js
___________________________________________________________________
Added: svn:eol-style
1377 + native
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedTypes.js
@@ -4,6 +4,32 @@
55 * http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/OggHandler/OggPlayer.js
66 */
77 ( function( mw, $ ) {
 8+
 9+/**
 10+ * Setup local players and supported mime types In an ideal world we would query the plugin
 11+ * to get what mime types it supports in practice not always reliable/available
 12+ *
 13+ * We can't cleanly store these values per library since player library is sometimes
 14+ * loaded post player detection
 15+ */
 16+// Flash based players:
 17+var kplayer = new mw.MediaPlayer('kplayer', ['video/x-flv', 'video/h264'], 'Kplayer');
 18+
 19+// Java based player
 20+var cortadoPlayer = new mw.MediaPlayer( 'cortado', ['video/ogg', 'audio/ogg', 'application/ogg'], 'Java' );
 21+
 22+// Native html5 players
 23+var oggNativePlayer = new mw.MediaPlayer( 'oggNative', ['video/ogg', 'audio/ogg', 'application/ogg' ], 'Native' );
 24+var h264NativePlayer = new mw.MediaPlayer( 'h264Native', ['video/h264'], 'Native' );
 25+var webmNativePlayer = new mw.MediaPlayer( 'webmNative', ['video/webm'], 'Native' );
 26+
 27+// VLC player
 28+var vlcMineList = ['video/ogg', 'audio/ogg', 'application/ogg', 'video/x-flv', 'video/mp4', 'video/h264', 'video/x-msvideo', 'video/mpeg'];
 29+var vlcPlayer = new mw.MediaPlayer( 'vlc-player', vlcMineList, 'Vlc' );
 30+
 31+// Generic plugin
 32+var oggPluginPlayer = new mw.MediaPlayer( 'oggPlugin', ['video/ogg', 'application/ogg'], 'Generic' );
 33+
834
935 mw.EmbedTypes = {
1036
@@ -28,7 +54,7 @@
2955 if( this.mediaPlayers ){
3056 return this.mediaPlayers;
3157 }
32 - this.mediaPlayers = new mediaPlayers();
 58+ this.mediaPlayers = new mw.MediaPlayers();
3359 // detect available players
3460 this.detectPlayers();
3561 return this.mediaPlayers;

Status & tagging log