First video is loaded in 1080p
than when I press a button with class="quality"
It should change the quality to 720p but it's not working in HTML5 player.
It works on Flash Player but not in HTML5. I'm using JavaScript Player API.
Note: None of these solutions worked for me. YouTube iFrame API "setPlaybackQuality" or "suggestedQuality" not working
function onPlayerReady(event) {
event.target.playVideo();
event.target.setPlaybackQuality('hd1080'); //works
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING) {
$(".quality").click(function() {
event.target.setPlaybackQuality('hd720'); //doesn't work
});
}
}
The problem is you can not downgrade quality. Once you set to 1080p for ex you can not go back to 720p.
Try stopping the video, then setting the playback quality, then resuming playback.
I have taken the example from this site YouTube Player API Reference for iframe Embeds. I have manually added one button to change the quality which is working absolutely fine, Here is the working code.
Initially onPlayerReady the quality is set to 360p. After clicking on Change Quality button the quality is set to 144p.