clappr / clappr-level-selector-plugin

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

Set default resolution and use auto resolution when enter full screen #44

Closed kulab45 closed 3 years ago

kulab45 commented 7 years ago

May I know how to set default resolution?

I've embedded the very small size player to my website (325x183) but the player always select the best resolution of my streaming to play (720p). So may I ask how to set default resolution to "360p" and when click full screen it'll change to "Auto" resolution by itself.

joaopaulovieira commented 4 years ago

I think this case is not the goal of the plugin but is possible to do this with the existing playback properties. The Clappr playbacks that have compatibility with this plugin have the property currentLevel and are possible to update via playback instance.

Example of a solution (tested this code on clappr.io/demo):

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] }
});

var levelWithoutFullscreen = 0

player.on(Clappr.Events.PLAYER_FULLSCREEN, function() {
  player.core.activePlayback.currentLevel = player.core.isFullscreen() ? -1 : levelWithoutFullscreen
})

player.attachTo(playerElement);

player.core.activePlayback.on(Clappr.Events.PLAYBACK_LEVELS_AVAILABLE, function(levels) {
  player.core.activePlayback.currentLevel = levelWithoutFullscreen
})