mirror of
https://github.com/kmoskwiak/videojs-resolution-switcher.git
synced 2025-10-03 09:49:21 +02:00
hls support
This commit is contained in:
parent
2e5bb5ade7
commit
18466b0b3b
2 changed files with 56 additions and 8 deletions
|
@ -33,7 +33,7 @@
|
|||
<video id="video" class="video-js"></video>
|
||||
|
||||
<script src="../node_modules/video.js/dist/video.js"></script>
|
||||
<script src="../node_modules/videojs-contrib-hls/dist/videojs.hls.min.js"></script>
|
||||
<script src="../node_modules/videojs-contrib-hls/dist/videojs.hls.js"></script>
|
||||
<script src="../lib/videojs-resolution-switcher.js"></script>
|
||||
<script>
|
||||
// fire up the plugin
|
||||
|
@ -52,7 +52,7 @@
|
|||
window.player = player
|
||||
|
||||
player.src({
|
||||
src: '//s3.amazonaws.com/_bc_dml/example-content/tears-of-steel/playlist.m3u8',
|
||||
src: '//labs.tvpw.pl/video/hls/tears.m3u8',
|
||||
type: 'application/x-mpegURL'
|
||||
})
|
||||
|
||||
|
|
|
@ -178,6 +178,7 @@
|
|||
player.controlBar.resolutionSwitcher.dispose();
|
||||
delete player.controlBar.resolutionSwitcher;
|
||||
}
|
||||
|
||||
//Sort sources
|
||||
src = src.sort(compareResolutions);
|
||||
groupedSrc = bucketSources(src);
|
||||
|
@ -340,12 +341,59 @@
|
|||
function initResolutionForHLS(player){
|
||||
var hls = player.tech_.hls;
|
||||
|
||||
// Capture events
|
||||
player.on('mediachange', function(){
|
||||
player.trigger('resolutionchange');
|
||||
});
|
||||
|
||||
player.one('loadedmetadata', function(){
|
||||
var playlists = hls.playlists.master.playlists;
|
||||
console.log(playlists)
|
||||
})
|
||||
|
||||
var _sources = [];
|
||||
playlists.map(function(value){
|
||||
_sources.push({
|
||||
src: value.uri,
|
||||
type: 'application/x-mpegURL',
|
||||
label: value.attributes.NAME || value.attributes.RESOLUTION.height,
|
||||
res: value.attributes.RESOLUTION.height
|
||||
});
|
||||
});
|
||||
|
||||
groupedSrc = bucketSources(_sources);
|
||||
|
||||
var selectPlaylist = function (selectedResolution){
|
||||
var _selectPlaylist = function (){
|
||||
return hls.playlists.master.playlists.filter(function (playlist) {
|
||||
return playlist.attributes.RESOLUTION.height === selectedResolution;
|
||||
})[0];
|
||||
};
|
||||
return _selectPlaylist;
|
||||
};
|
||||
|
||||
// Overwrite defualt sourcePicer function
|
||||
var _customSourcePicker = function(_player, _sources, _label){
|
||||
var selectedRes = _sources[0].res;
|
||||
hls.selectPlaylist = selectPlaylist(selectedRes);
|
||||
return player;
|
||||
};
|
||||
|
||||
var currentPlaylist = hls.playlists.media();
|
||||
var choosen = {
|
||||
label: currentPlaylist.attributes.NAME || currentPlaylist.attributes.RESOLUTION.height,
|
||||
res: currentPlaylist.attributes.RESOLUTION.height,
|
||||
sources: currentPlaylist
|
||||
};
|
||||
|
||||
var menuButton = new ResolutionMenuButton(player, {
|
||||
sources: groupedSrc,
|
||||
initialySelectedLabel: choosen.label,
|
||||
initialySelectedRes: choosen.res,
|
||||
customSourcePicker: _customSourcePicker
|
||||
}, settings, label);
|
||||
|
||||
menuButton.el().classList.add('vjs-resolution-button');
|
||||
player.controlBar.resolutionSwitcher = player.controlBar.addChild(menuButton);
|
||||
});
|
||||
}
|
||||
|
||||
player.ready(function(){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue