r37738 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37737‎ | r37738 | r37739 >
Date:06:54, 16 July 2008
Author:stipe
Status:old
Tags:
Comment:
added playable_sources, separated download / play selection displays, currently selected source is indicated on selection display
Modified paths:
  • /branches/MetavidWiki-exp/MetavidWiki/skins/mv_embed/mv_embed.js (modified) (history)

Diff [purge]

Index: branches/MetavidWiki-exp/MetavidWiki/skins/mv_embed/mv_embed.js
@@ -1138,6 +1138,7 @@
11391139 start_offset:null,
11401140 /** Duration of the requested segment (NaN if not known) */
11411141 duration:NaN,
 1142+ is_playable:null,
11421143
11431144 id:null,
11441145 start_ntp:null,
@@ -1155,19 +1156,25 @@
11561157 if (tag == 'video')
11571158 this.marked_default = true;
11581159
 1160+ if (element.hasAttribute('type'))
 1161+ this.mime_type = element.getAttribute('type');
 1162+ else if (element.hasAttribute('content-type'))
 1163+ this.mime_type = element.getAttribute('content-type');
 1164+ else
 1165+ this.mime_type = this.detectType(this.uri);
 1166+
11591167 if (element.hasAttribute("title"))
11601168 this.title = element.getAttribute("title");
11611169 else
1162 - this.title = this.uri;
 1170+ {
 1171+ var parts = this.mime_type.split("/",2);
 1172+ parts[0]=parts[0].replace('video', 'stream');
 1173+ parts[1]=parts[1].replace('x-flv', 'flash');
 1174+ this.title = parts[1] + ' ' + parts[0];
 1175+ }
11631176 if (element.hasAttribute("id"))
11641177 this.id = element.getAttribute("id");
11651178
1166 - if (element.hasAttribute('type'))
1167 - this.mime_type = element.getAttribute('type');
1168 - else if (element.hasAttribute('content-type'))
1169 - this.mime_type = element.getAttribute('content-type');
1170 - else
1171 - this.mime_type = this.detectType(this.uri);
11721179 js_log('Adding mediaSource of type ' + this.mime_type + ' and uri ' + this.uri + ' and title ' + this.title);
11731180 this.parseURLDuration();
11741181 },
@@ -1289,6 +1296,8 @@
12901297 {
12911298 /** The array of mediaSource elements. */
12921299 sources:null,
 1300+ /** Playable sources **/
 1301+ playable_sources:null,
12931302 /** Selected mediaSource element. */
12941303 selected_source:null,
12951304 thumbnail:null,
@@ -1300,6 +1309,7 @@
13011310 var _this = this;
13021311 js_log('Initializing mediaElement...');
13031312 this.sources = new Array();
 1313+ this.playable_sources = new Array();
13041314 this.thumbnail = mv_default_thumb_url;
13051315 // Process the <video> element
13061316 this.tryAddSource(video_element);
@@ -1322,14 +1332,14 @@
13231333 });
13241334 }
13251335 // Select the default source
1326 - for (var source in this.sources)
1327 - if(this.sources[source].marked_default)
1328 - this.selected_source = this.sources[source];
 1336+ for (var source in this.playable_sources)
 1337+ if(this.playable_sources[source].marked_default)
 1338+ this.selected_source = this.playable_sources[source];
13291339 // or the first source
13301340 if (!this.selected_source)
13311341 {
13321342 js_log('autoselecting first source');
1333 - this.selected_source = this.sources[0];
 1343+ this.selected_source = this.playable_sources[0];
13341344 }
13351345 },
13361346 /** Updates the time request for all sources that have a standard time request argument (ie &t=start_time/end_time)
@@ -1374,6 +1384,10 @@
13751385 }
13761386 return false;
13771387 },
 1388+ isPlayableType:function(mime_type)
 1389+ {
 1390+ return mime_type=='video/ogg' || mime_type=='video/annodex' || mime_type=='video/x-flv';
 1391+ },
13781392 /** Adds a single mediaSource using the provided element if
13791393 the element has a 'src' attribute.
13801394 @param element {element} <video>, <source> or <mediaSource> element.
@@ -1382,7 +1396,10 @@
13831397 {
13841398 if (!element.hasAttribute('src'))
13851399 return;
1386 - this.sources.push(new mediaSource(element));
 1400+ var source = new mediaSource(element);
 1401+ this.sources.push(source);
 1402+ if(this.isPlayableType(source.mime_type))
 1403+ this.playable_sources.push(source);
13871404 },
13881405 /** Imports media sources from ROE data.
13891406 @param roe_data ROE data.
@@ -1818,20 +1835,36 @@
18191836 },
18201837 selectPlaybackMethod:function(){
18211838 var _this=this;
1822 - var select_code=this.getDLlist(function(index, source)
 1839+ var select_code=this.getPlaybackMethodList(function(index, source)
18231840 {
18241841 var default_player = embedTypes.players.defaultPlayer(source.getMIMEType());
18251842 var source_select_code = 'document.getElementById(\''+_this.id+'\').closeDisplayedHTML(); document.getElementById(\''+_this.id+'\').media_element.selectSource(\''+index+'\');';
18261843 var player_code = _this.getPlayerSelectList(source.getMIMEType(), index, source_select_code);
 1844+ var is_not_selected = (source != _this.media_element.selected_source);
18271845 if (default_player)
1828 - return '<a href="#" onClick="' + source_select_code + 'embedTypes.players.userSelectPlayer(\''+default_player.id+'\',\''+source.getMIMEType()+'\'); return false;">'
1829 - + source.getTitle()+' - ' + default_player.getName() + '</a> '
1830 - + '(<a href="#" onClick=\'$j("#player_select_list_'+index+'").fadeIn("slow");return false;\'>choose player</a>)' + player_code;
 1846+ {
 1847+ var retval = '';
 1848+ if(is_not_selected)
 1849+ retval+='<a href="#" onClick="' + source_select_code + 'embedTypes.players.userSelectPlayer(\''+default_player.id+'\',\''+source.getMIMEType()+'\'); return false;">';
 1850+ retval += source.getTitle()+' - ' + default_player.getName() + (is_not_selected?'</a>':'') + ' ';
 1851+ retval += '(<a href="#" onClick=\'$j("#player_select_list_'+index+'").fadeIn("slow");return false;\'>choose player</a>)' + player_code;
 1852+ return retval;
 1853+ }
18311854 else
18321855 return source.getTitle() + ' - no player available';
18331856 });
18341857 this.displayHTML(select_code);
18351858 },
 1859+ getPlaybackMethodList:function(transform_function){
 1860+ var out='<span style="color:white"><blockquote>';
 1861+ var _this=this;
 1862+ $j.each(this.media_element.playable_sources, function(index, source)
 1863+ {
 1864+ out+='<li>' + transform_function(index, source) + '</li>'+"\n";
 1865+ });
 1866+ out+='</blockquote></span>';
 1867+ return out;
 1868+ },
18361869 showVideoDownload:function(){
18371870 var select_code=this.getDLlist(function(index, source)
18381871 {
@@ -1840,11 +1873,8 @@
18411874 });
18421875 this.displayHTML(select_code);
18431876 },
1844 - /*
1845 - * Its pretty confusing to merge getDLlist with selectPlaybackMethod
1846 - */
18471877 getDLlist:function(transform_function){
1848 - var out='<b style="color:white;">'+getMsg('download_from')+' '+parseUri(this.src).queryKey['t']+'</b><br>';
 1878+ var out='<b style="color:white;">'+getMsg('download_from')/*+' '+parseUri(this.src).queryKey['t']*/+'</b><br>';
18491879 out+='<span style="color:white"><blockquote>';
18501880 var dl_list=dl_txt_list='';
18511881 $j.each(this.media_element.getSources(), function(index, source)

Status & tagging log