r80284 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80283‎ | r80284 | r80285 >
Date:18:07, 14 January 2011
Author:dale
Status:deferred
Tags:
Comment:
bug 26663 ( adds basic temporal url support )
Modified paths:
  • /branches/MwEmbedStandAlone/modules/EmbedPlayer/mw.EmbedPlayer.js (modified) (history)
  • /branches/MwEmbedStandAlone/mwEmbed.js (modified) (history)
  • /branches/MwEmbedStandAlone/remotes/mediaWiki.js (modified) (history)

Diff [purge]

Index: branches/MwEmbedStandAlone/mwEmbed.js
@@ -1804,8 +1804,8 @@
18051805 */
18061806 mw.npt2seconds = function ( npt_str ) {
18071807 if ( !npt_str ) {
1808 - // mw.log('npt2seconds:not valid ntp:'+ntp);
1809 - return false;
 1808+ mw.log('npt2seconds:not valid ntp:'+ntp);
 1809+ return 0;
18101810 }
18111811 // Strip {npt:}01:02:20 or 32{s} from time if present
18121812 npt_str = npt_str.replace( /npt:|s/g, '' );
Index: branches/MwEmbedStandAlone/modules/EmbedPlayer/mw.EmbedPlayer.js
@@ -988,6 +988,7 @@
989989 */
990990 autoSelectSource: function() {
991991 mw.log( 'EmbedPlayer::mediaElement::autoSelectSource' );
 992+ var _this = this;
992993 // Select the default source
993994 var playableSources = this.getPlayableSources();
994995 var flash_flag = ogg_flag = false;
@@ -996,13 +997,16 @@
997998 if( playableSources.length == 0 ){
998999 return false;
9991000 }
 1001+ var setSelectedSource = function( source ){
 1002+ _this.selectedSource = source;
 1003+ };
10001004
10011005 // Set via user-preference
10021006 for ( var source = 0; source < playableSources.length; source++ ) {
10031007 var mimeType = playableSources[source].mimeType;
10041008 if ( mw.EmbedTypes.players.preference[ 'format_preference' ] == mimeType ) {
1005 - mw.log( 'Set via preference: ' + playableSources[source].mimeType );
1006 - this.selectedSource = playableSources[source];
 1009+ mw.log( 'EmbedPlayer::autoSelectSource: Set via preference: ' + playableSources[source].mimeType );
 1010+ setSelectedSource( playableSources[source] );
10071011 return true;
10081012 }
10091013 }
@@ -1010,8 +1014,8 @@
10111015 // Set via marked default:
10121016 for ( var source = 0; source < playableSources.length; source++ ) {
10131017 if ( playableSources[ source ].markedDefault ) {
1014 - mw.log( 'Set via marked default: ' + playableSources[source].markedDefault );
1015 - this.selectedSource = playableSources[source];
 1018+ mw.log( 'EmbedPlayer::autoSelectSource: Set via marked default: ' + playableSources[source].markedDefault );
 1019+ setSelectedSource( playableSources[source] );
10161020 return true;
10171021 }
10181022 }
@@ -1021,8 +1025,8 @@
10221026 var mimeType = playableSources[source].mimeType;
10231027 var player = mw.EmbedTypes.players.defaultPlayer( mimeType );
10241028 if ( player && player.library == 'Native' ) {
1025 - mw.log('EmbedPlayer::Set native playback');
1026 - this.selectedSource = playableSources[ source ];
 1029+ mw.log('EmbedPlayer::autoSelectSource: Set via native playback');
 1030+ setSelectedSource( playableSources[ source ] );
10271031 return true;
10281032 }
10291033 }
@@ -1039,16 +1043,16 @@
10401044 player.library == 'Kplayer'
10411045 )
10421046 ) {
1043 - mw.log('Set h264 via native or flash fallback');
1044 - this.selectedSource = playableSources[ source ];
 1047+ mw.log('EmbedPlayer::autoSelectSource: Set h264 via native or flash fallback');
 1048+ setSelectedSource( playableSources[ source ] );
10451049 return true;
10461050 }
10471051 };
10481052
10491053 // Else just select first source
10501054 if ( !this.selectedSource ) {
1051 - mw.log( 'set via first source:' + playableSources[0] );
1052 - this.selectedSource = playableSources[0];
 1055+ mw.log( 'EmbedPlayer::autoSelectSource: Set via first source:' + playableSources[0] );
 1056+ setSelectedSource( playableSources[0] );
10531057 return true;
10541058 }
10551059 // No Source found so no source selected
@@ -1255,7 +1259,10 @@
12561260 // Buffer flags
12571261 'bufferStartFlag' : false,
12581262 'bufferEndFlag' : false,
1259 -
 1263+
 1264+ // For supporting media fragments stores the play end time
 1265+ 'pauseTime' : null,
 1266+
12601267 // On done playing
12611268 'donePlayingCount' : 0
12621269 ,
@@ -2050,17 +2057,51 @@
20512058 this.$interface.hide();
20522059 }
20532060
 2061+ // Update temporal url if present
 2062+ this.updateTemporalUrl();
 2063+
 2064+
20542065 if ( this.autoplay ) {
20552066 mw.log( 'EmbedPlayer::showPlayer::activating autoplay' );
20562067 // Issue a non-blocking play request
20572068 setTimeout(function(){
20582069 _this.play();
2059 - },1)
 2070+ },1);
20602071 }
20612072
20622073 },
2063 -
20642074 /**
 2075+ * Media framgments handler based on:
 2076+ * http://www.w3.org/2008/WebVideo/Fragments/WD-media-fragments-spec/#fragment-dimensions
 2077+ *
 2078+ * We support seconds and npt ( normal play time )
 2079+ *
 2080+ * Updates the player per fragment url info if present
 2081+ *
 2082+ */
 2083+ updateTemporalUrl: function(){
 2084+ var sourceHash = /[^\#]+$/.exec( this.getSrc() ).toString();
 2085+ if( sourceHash.indexOf('t=') === 0 ){
 2086+ // parse the times
 2087+ var times = sourceHash.substr(2).split(',');
 2088+ if( times[0] ){
 2089+ // update the current time
 2090+ this.currentTime = mw.npt2seconds( times[0].toString() );
 2091+ }
 2092+ if( times[1] ){
 2093+ this.pauseTime = mw.npt2seconds( times[1].toString() );
 2094+ // ignore invalid ranges:
 2095+ if( this.pauseTime < this.currentTime ){
 2096+ this.pauseTime = null;
 2097+ }
 2098+ }
 2099+ // Update the play head
 2100+ this.updatePlayHead( this.currentTime / this.duration );
 2101+ // Update status:
 2102+ this.controlBuilder.setStatus( mw.seconds2npt( this.currentTime ) );
 2103+ }
 2104+ },
 2105+ /**
20652106 * Get missing plugin html (check for user included code)
20662107 *
20672108 * @param {String}
@@ -2953,6 +2994,11 @@
29542995 // Update the previousTime ( so we can know if the user-javascript
29552996 // changed currentTime )
29562997 _this.previousTime = _this.currentTime;
 2998+
 2999+ if( _this.pauseTime && _this.currentTime > _this.pauseTime ){
 3000+ _this.pause();
 3001+ _this.pauseTime = null;
 3002+ }
29573003
29583004
29593005 // Check if volume was set outside of embed player function
@@ -3110,68 +3156,8 @@
31113157 $j( this ).trigger('updatePlayHeadPercent', perc);
31123158 },
31133159
3114 - /**
3115 - * Highlight a section of video on the playhead
3116 - *
3117 - * @param {Object}
3118 - * options Provides "start" time & "end" time to highlight
3119 - */
3120 - highlightPlaySection:function( options ) {
3121 - mw.log( 'highlightPlaySection' );
3122 - var eid = ( this.pc ) ? this.pc.pp.id:this.id;
3123 - var dur = this.getDuration();
3124 - // set the left percet and update the slider:
3125 - rel_start_sec = mw.npt2seconds( options['start'] );
3126 - // remove the startOffset if relevent:
3127 - if ( this.startOffset )
3128 - rel_start_sec = rel_start_sec - this.startOffset
31293160
3130 - var slider_perc = 0;
3131 - if ( rel_start_sec <= 0 ) {
3132 - left_perc = 0;
3133 - options['start'] = mw.seconds2npt( this.startOffset );
3134 - rel_start_sec = 0;
3135 - this.updatePlayHead( 0 );
3136 - } else {
3137 - left_perc = parseInt( ( rel_start_sec / dur ) * 100 ) ;
3138 - slider_perc = ( left_perc / 100 );
3139 - }
3140 -
3141 - mw.log( "slider perc:" + slider_perc );
3142 - if ( ! this.isPlaying() ) {
3143 - this.updatePlayHead( slider_perc );
3144 - }
3145 -
3146 - width_perc = parseInt( ( ( mw.npt2seconds( options['end'] ) - mw.npt2seconds( options['start'] ) ) / dur ) * 100 ) ;
3147 - if ( ( width_perc + left_perc ) > 100 ) {
3148 - width_perc = 100 - left_perc;
3149 - }
3150 - // mw.log('should hl: '+rel_start_sec+ '/' + dur + ' re:' +
3151 - // rel_end_sec+' lp:' + left_perc + ' width: ' + width_perc);
3152 - $j( '#mv_seeker_' + eid + ' .mv_highlight' ).css( {
3153 - 'left' : left_perc + '%',
3154 - 'width' : width_perc + '%'
3155 - } ).show();
3156 -
3157 - this.jump_time = options['start'];
3158 - this.serverSeekTime = mw.npt2seconds( options['start'] );
3159 - // trim output to
3160 - this.controlBuilder.setStatus( gM( 'mwe-embedplayer-seek_to', mw.seconds2npt( this.serverSeekTime ) ) );
3161 - mw.log( 'DO update: ' + this.jump_time );
3162 - this.updateThumbTime( rel_start_sec );
3163 - },
3164 -
31653161 /**
3166 - * Hides the playhead highlight
3167 - */
3168 - hideHighlight: function() {
3169 - var eid = ( this.pc ) ? this.pc.pp.id:this.id;
3170 - $j( '#mv_seeker_' + eid + ' .mv_highlight' ).hide();
3171 - this.controlBuilder.setStatus( this.getTimeRange() );
3172 - },
3173 -
3174 -
3175 - /**
31763162 * Helper Functions for selected source
31773163 */
31783164
Index: branches/MwEmbedStandAlone/remotes/mediaWiki.js
@@ -458,8 +458,8 @@
459459 timeHash= '#t=' + $startTime.text();
460460 // if we have a start time also look for endtime
461461 var $endTime = $j( '#' + vidId ).parent().find('.endtime');
462 - if( $endTime.lenght ){
463 - timeHash += $endTime.text();
 462+ if( $endTime.length ){
 463+ timeHash += ',' + $endTime.text();
464464 }
465465 }
466466 // Update the video source with the temporal time hash:

Status & tagging log