clappr / clappr-level-selector-plugin

Clappr Level Selector Plugin
MIT License
76 stars 56 forks source link

How can I change the quality level by program code? #53

Closed gaalgergely closed 4 years ago

gaalgergely commented 7 years ago

I would like to change the quality level from javascript code. It is about having a setting that uses low quality. It is stored in localStorage. How can I do that?

joaopaulovieira commented 4 years ago

One way to do before the Clappr starts to play it would be like this:

var playerElement = document.getElementById("player-wrapper");

var player = new Clappr.Player({
  source: 'https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8',
  poster: 'http://clappr.io/poster.png',
  mute: true,
  height: 360,
  width: 640,
  plugins: {core: [LevelSelector]}
});

player.attachTo(playerElement);

player.core.activePlayback.on(Clappr.Events.PLAYBACK_LEVELS_AVAILABLE, function(levels) {
  player.core.activePlayback.currentLevel = 1 // Your preferred level here
})

And to change the current level in the middle of the video, just set the desired level on currentLevel playback property. Like: player.core.activePlayback.currentLevel = 'preferred level'

gaalgergely commented 4 years ago

Thanks!