Blame view

sources/apps/files_videoviewer/mediaelement/src/js/mep-feature-sourcechooser.js 2.58 KB
42e4f8d60   Kload   add all apps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  // Source Chooser Plugin
  (function($) {
  
  	$.extend(mejs.MepDefaults, {
  		sourcechooserText: 'Source Chooser'
  	});
  
  	$.extend(MediaElementPlayer.prototype, {
  		buildsourcechooser: function(player, controls, layers, media) {
  
  			var t = this;
  
  			player.sourcechooserButton =
  				$('<div class="mejs-button mejs-sourcechooser-button">'+
  					'<button type="button" aria-controls="' + t.id + '" title="' + t.options.sourcechooserText + '" aria-label="' + t.options.sourcechooserText + '"></button>'+
  					'<div class="mejs-sourcechooser-selector">'+
  						'<ul>'+
  						'</ul>'+
  					'</div>'+
  				'</div>')
  					.appendTo(controls)
  
  					// hover
  					.hover(function() {
  						$(this).find('.mejs-sourcechooser-selector').css('visibility','visible');
  					}, function() {
  						$(this).find('.mejs-sourcechooser-selector').css('visibility','hidden');
  					})
  
  					// handle clicks to the language radio buttons
  					.delegate('input[type=radio]', 'click', function() {
  						src = this.value;
  
  						if (media.currentSrc != src) {
  							currentTime = media.currentTime;
  							paused = media.paused;
  							media.setSrc(src);
  							media.load();
  							media.addEventListener('loadedmetadata', function(e){
  				                this.currentTime = currentTime;
  				            }, true);
  				            media.addEventListener('canplay', function(e){
  				            	if (!paused) {
  					            	this.play();
  					            }
  				            }, true);
  						}
  					});
  
  			// add to list
  			for (i in media.children) {
  				src = media.children[i];
  				if (src.nodeName === 'SOURCE' && (media.canPlayType(src.type) == 'probably' || media.canPlayType(src.type) == 'maybe')) {
  					player.addSourceButton(src.src, src.title, src.type, media.src == src.src);
  				}
  			}
  
  		},
  
  		addSourceButton: function(src, label, type, isCurrent) {
  			var t = this;
  			if (label === '' || label == undefined) {
  				label = src;
  			}
  			type = type.split('/')[1];
  
  			t.sourcechooserButton.find('ul').append(
  				$('<li>'+
  					'<input type="radio" name="' + t.id + '_sourcechooser" id="' + t.id + '_sourcechooser_' + label + type + '" value="' + src + '" ' + (isCurrent ? 'checked="checked"' : '') + ' />'+
  					'<label for="' + t.id + '_sourcechooser_' + label + type + '">' + label + ' (' + type + ')</label>'+
  				'</li>')
  			);
  
  			t.adjustSourcechooserBox();
  
  		},
  
  		adjustSourcechooserBox: function() {
  			var t = this;
  			// adjust the size of the outer box
  			t.sourcechooserButton.find('.mejs-sourcechooser-selector').height(
  				t.sourcechooserButton.find('.mejs-sourcechooser-selector ul').outerHeight(true)
  			);
  		}
  	});
  
  })(mejs.$);