Last active
February 23, 2018 16:37
-
-
Save MCheli/82a1e8aade60c80b1e10caf1597aac9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get a reference to the player | |
var myPlayer = videojs("S1LnMbpBz"), | |
options = {}; | |
// +++ Define the playback rate options +++ | |
options = { playbackRates: [0.5, 0.75, 1, 1.25, 1.5, 2] }; | |
// +++ Turn off the default source order +++ | |
if (Array.isArray(options.playbackRates)) { | |
// Set sourceOrder to false - this means old browsers that support HLS in Flash but not HTML5/MSE will use MP4. | |
// IE will use MP4/HTML5 before HLS/Flash | |
myPlayer.options_.sourceOrder = false; | |
// +++ Update the existing playback rate menu +++ | |
if (myPlayer.controlBar.playbackRateMenuButton) { | |
var playbackControl = myPlayer.controlBar.playbackRateMenuButton; | |
playbackControl.removeChild(playbackControl.menu); | |
playbackControl.options_.playbackRates = options.playbackRates; | |
playbackControl.addChild(playbackControl.createMenu()); | |
playbackControl.updateLabel(); | |
playbackControl.updateVisibility(); | |
} else { | |
// +++ Add the playback rate menu +++ | |
myPlayer.controlBar.playbackRateMenuButton = myPlayer.controlBar.addChild( | |
"PlaybackRateMenuButton", | |
{ | |
playbackRates: options.playbackRates | |
} | |
); | |
myPlayer.controlBar.playbackRateMenuButton.updateVisibility(); | |
} | |
} | |
// +++ Support for IE browsers +++ | |
// This section is to keep the selected rate value from resetting to 1x when you pause and play in IE | |
if (videojs.browser.IE_VERSION) { | |
console.log("IE_VERSION"); | |
//get method for selected playback rate value | |
function getPlayBackRate() { | |
rateEl = document.getElementsByClassName("vjs-playback-rate-value")[0]; | |
rateValue = rateEl.innerText.substr(0, rateEl.innerText.length - 1); | |
return rateValue; | |
} | |
//get playback value when paused | |
myPlayer.on("pause", function() { | |
rateValue = getPlayBackRate(); | |
}); | |
myPlayer.on("ratechange", function() { | |
//get new playback rate if the player is paused | |
if (myPlayer.paused()) { | |
rateValue = getPlayBackRate(); | |
} | |
}); | |
//set backuped playback rate when playback starts | |
myPlayer.on("play", function() { | |
myPlayer.playbackRate(rateValue); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment