r91852 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91851‎ | r91852 | r91853 >
Date:23:44, 10 July 2011
Author:dale
Status:deferred
Tags:
Comment:
some minor changes / refactor to mediaElement and mediaSource per sync efforts with html5.kaltura branch
more robust handling of element data and support for video/ogg; codecs=theora style source type tags
Modified paths:
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaSource.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedTextPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TimedMediaHandler/TimedTextPage.php
@@ -74,6 +74,6 @@
7575 if( !$this->exists() ){
7676 return wfMessage( 'timedmedia-subtitle-no-subtitles', $languageName );
7777 }
78 - return '<pre style="margin-top:0px;">'. $this->getContent() . "</pre>";
 78+ return '<pre style="margin-top:0px;">'. $this->getContent() . '</pre>'';
7979 }
8080 }
\ No newline at end of file
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaElement.js
@@ -43,14 +43,16 @@
4444 this.sources = new Array();
4545
4646 // Process the videoElement as a source element:
47 - if ( $( videoElement ).attr( "src" ) ) {
48 - _this.tryAddSource( videoElement );
 47+ if( videoElement ){
 48+ if ( $( videoElement ).attr( "src" ) ) {
 49+ _this.tryAddSource( videoElement );
 50+ }
 51+
 52+ // Process elements source children
 53+ $( videoElement ).find( 'source,track' ).each( function( ) {
 54+ _this.tryAddSource( this );
 55+ } );
4956 }
50 -
51 - // Process elements source children
52 - $( videoElement ).find( 'source,track' ).each( function( ) {
53 - _this.tryAddSource( this );
54 - } );
5557 },
5658
5759 /**
@@ -113,7 +115,7 @@
114116 * Selects a source by id
115117 *
116118 * @param {String}
117 - * source_id Id of the source to select.
 119+ * sourceId Id of the source to select.
118120 * @return {MediaSource} The selected mediaSource or null if not found
119121 */
120122 getSourceById:function( sourceId ) {
@@ -167,8 +169,7 @@
168170 var _this = this;
169171 // Select the default source
170172 var playableSources = this.getPlayableSources();
171 - var flash_flag, oggflag;
172 - flash_flag = ogg_flag = false;
 173+ var flash_flag = ogg_flag = false;
173174
174175 // Check if there are any playableSources
175176 if( playableSources.length == 0 ){
@@ -176,25 +177,25 @@
177178 }
178179 var setSelectedSource = function( source ){
179180 _this.selectedSource = source;
 181+ return true;
180182 };
181 -
 183+
182184 // Set via user-preference
183185 $.each( playableSources, function( inx, source ){
184186 var mimeType =source.mimeType;
185187 if ( mw.EmbedTypes.getMediaPlayers().preference[ 'format_preference' ] == mimeType ) {
186188 mw.log( 'MediaElement::autoSelectSource: Set via preference: ' + source.mimeType );
187 - setSelectedSource( source );
188 - return true;
 189+ return setSelectedSource( source );
189190 }
190191 });
191 -
 192+
192193 // Set via module driven preference:
193194 $(this).trigger( 'AutoSelectSource', [ playableSources ] );
194195 if( _this.selectedSource ){
195196 mw.log('MediaElement::autoSelectSource: Set via trigger::' );
196197 return true;
197198 }
198 -
 199+
199200 // Set via marked default:
200201 $.each( playableSources, function( inx, source ){
201202 if ( source.markedDefault ) {
@@ -203,7 +204,7 @@
204205 return true;
205206 }
206207 });
207 -
 208+
208209 //Set via user bandwith pref
209210 if( $.cookie('EmbedPlayer.UserBandwidth') ){
210211 $.each( playableSources, function(inx, source ){
@@ -244,30 +245,32 @@
245246 var namedSources = [];
246247 $.each( playableSources, function(inx, source ){
247248 var mimeType = source.mimeType;
248 - var player = mw.EmbedTypes.getMediaPlayers().defaultPlayer( mimeType );
 249+ var player = mw.EmbedTypes.getMediaPlayers().defaultPlayer( mimeType );
249250 if ( player && player.library == 'Native' ) {
250251 switch( player.id ){
251 - case 'oggNative':
252 - namedSources['ogg'] = source;
 252+ case 'mp3Native':
 253+ namedSources['mp3'] = playableSources[ source ];
253254 break;
 255+ case 'oggNative':
 256+ namedSources['ogg'] = playableSources[ source ];
 257+ break;
254258 case 'webmNative':
255 - namedSources['webm'] = source;
 259+ namedSources['webm'] = playableSources[ source ];
256260 break;
257261 case 'h264Native':
258 - namedSources['h264'] = source;
 262+ namedSources['h264'] = playableSources[ source ];
259263 break;
260264 }
261265 }
262266 });
 267+
263268 var codecPref =mw.getConfig( 'EmbedPlayer.CodecPreference');
264269 for(var i =0; i < codecPref.length; i++){
265270 var codec = codecPref[ i ];
266271 if( namedSources[ codec ]){
267 - setSelectedSource( namedSources[ codec ] );
268 - return true;
 272+ return setSelectedSource( namedSources[ codec ] );
269273 }
270274 };
271 -
272275
273276 // Set h264 via native or flash fallback
274277 $.each( playableSources, function(inx, source ){
@@ -282,16 +285,14 @@
283286 )
284287 ) {
285288 mw.log('MediaElement::autoSelectSource: Set h264 via native or flash fallback');
286 - setSelectedSource( source );
287 - return true;
 289+ return setSelectedSource( playableSources[ source ] );
288290 }
289291 });
290292
291293 // Else just select first source
292 - if ( !this.selectedSource ) {
 294+ if ( !this.selectedSource && playableSources[0] ) {
293295 mw.log( 'MediaElement::autoSelectSource: Set via first source:' + playableSources[0] );
294 - setSelectedSource( playableSources[0] );
295 - return true;
 296+ return setSelectedSource( playableSources[0] );
296297 }
297298 // No Source found so no source selected
298299 return false;
@@ -389,10 +390,12 @@
390391 for ( var i = 0; i < this.sources.length; i++ ) {
391392 if ( this.isPlayableType( this.sources[i].mimeType ) ) {
392393 playableSources.push( this.sources[i] );
393 - }
 394+ } else {
 395+ mw.log( "type " + this.sources[i].mimeType + ' is not playable' );
 396+ }
394397 };
395398 return playableSources;
396 - }
 399+ }
397400 };
398401
399402 } )( mediaWiki, jQuery );
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.MediaSource.js
@@ -57,9 +57,18 @@
5858
5959 mw.MediaSource = function( element ) {
6060 this.init( element );
61 -}
 61+};
6262
6363 mw.MediaSource.prototype = {
 64+ // MIME type of the source.
 65+ mimeType:null,
 66+
 67+ // URI of the source.
 68+ uri:null,
 69+
 70+ // Title of the source.
 71+ title: null,
 72+
6473 // True if the source has been marked as the default.
6574 markedDefault: false,
6675
@@ -72,10 +81,25 @@
7382 // Duration of the requested segment (0 if not known)
7483 duration:0,
7584
 85+ // Is the source playable
 86+ is_playable: null,
 87+
 88+ // source id
 89+ id: null,
 90+
 91+ // Start time in npt format
 92+ start_npt: null,
 93+
 94+ // End time in npt format
 95+ end_npt: null,
 96+
 97+ // Language of the file
 98+ srclang: null,
7699 /**
77100 * MediaSource constructor:
78101 */
79102 init : function( element ) {
 103+ var _this = this;
80104 // mw.log('EmbedPlayer::adding mediaSource: ' + element);
81105 this.src = $( element ).attr( 'src' );
82106
@@ -88,16 +112,19 @@
89113 }
90114
91115 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 ) {
 116+ $.each(sourceAttr, function(inx, attr){
 117+ if ( $j( element ).attr( attr ) ) {
96118 // strip data- from the attribute name
97119 if( attr.indexOf('data-') === 0){
98120 attr = attr.substr(5);
99121 }
100 - this[ attr ] = attrValue;
 122+ _this[ attr ] = $j( element ).attr( attr );
101123 }
 124+ });
 125+
 126+ // Normalize "label" to "title" ( label is the actual spec so use that over title )
 127+ if( this.label ){
 128+ this.title = this.label;
102129 }
103130
104131 // Set the content type:
@@ -120,6 +147,12 @@
121148 if( this.mimeType == 'audio/vorbis') {
122149 this.mimeType = 'audio/ogg';
123150 }
 151+
 152+ // Conform long form "video/ogg; codecs=theora" based attributes
 153+ // @@TODO we should support codec in the type arguments
 154+ if( this.mimeType ){
 155+ this.mimeType = this.mimeType.split(';')[0];
 156+ }
124157
125158 // Check for parent elements ( supplies categories in "track" )
126159 if( $( element ).parent().attr('category') ) {
@@ -259,6 +292,12 @@
260293 case 'audio/ogg' :
261294 return gM( 'mwe-embedplayer-video-audio' );
262295 break;
 296+ case 'audio/mpeg' :
 297+ return 'MPEG audio'; // FIXME: i18n
 298+ break;
 299+ case 'video/3gp' :
 300+ return '3gp video'; // FIXME: i18n
 301+ break;
263302 case 'video/mpeg' :
264303 return 'MPEG video'; // FIXME: i18n
265304 break;
@@ -306,8 +345,17 @@
307346 }
308347 }
309348 },
310 -
311349 /**
 350+ * Get the extension of a url
 351+ * @param String uri
 352+ */
 353+ getExt : function( uri ){
 354+ var urlParts = new mw.Uri( uri );
 355+ // Get the extension from the url or from the relative name:
 356+ var ext = ( urlParts.file )? /[^.]+$/.exec( urlParts.file ) : /[^.]+$/.exec( uri );
 357+ return ext.toString().toLowerCase()
 358+ },
 359+ /**
312360 * Attempts to detect the type of a media file based on the URI.
313361 *
314362 * @param {String}
@@ -319,15 +367,7 @@
320368 // we can issue a HEAD request and read the mime type of the media...
321369 // ( this will detect media mime type independently of the url name )
322370 // 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() ) {
 371+ switch( this.getExt( uri ) ) {
332372 case 'smil':
333373 case 'sml':
334374 return 'application/smil';
@@ -336,9 +376,15 @@
337377 case 'mp4':
338378 return 'video/h264';
339379 break;
 380+ case 'm3u8':
 381+ return 'application/vnd.apple.mpegurl';
 382+ break;
340383 case 'webm':
341384 return 'video/webm';
342385 break;
 386+ case '3gp':
 387+ return 'video/3gp';
 388+ break;
343389 case 'srt':
344390 return 'text/x-srt';
345391 break;
@@ -352,6 +398,9 @@
353399 case 'oga':
354400 return 'audio/ogg';
355401 break;
 402+ case 'mp3':
 403+ return 'audio/mpeg';
 404+ break;
356405 case 'anx':
357406 return 'video/ogg';
358407 break;

Status & tagging log