Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setPlaybackQuality not changing quality

I'm trying to change the playback quality of a Youtube video using the iframe/javascript API.

However, the API seems to ignore my request. Here's a simple example:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div id="player"></div>

    <script>
      // 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');

      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      // 3. This function creates an <iframe> (and YouTube player)
      //    after the API code downloads.
      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '360',
          width: '640',
          videoId: 'M7lc1UVf-VE',
          events: {
            'onReady': onPlayerReady,
            'onPlaybackQualityChange': onPlaybackQualityChange
          }
        });
      }
      function changeQuality() {
        var qualities = player.getAvailableQualityLevels();
        var actual = player.getPlaybackQuality();
        for (var i = 0; i < qualities.length; i += 1) {
          if (actual !== qualities[i]) {
            console.log('Changing quality to:' + qualities[i]);
            //onPlaybackQualityChange is never called!
            player.setPlaybackQuality(qualities[i]);
            break;
          }
        }
      }
      function onPlayerReady(event) {
        event.target.playVideo();
        setTimeout(changeQuality, 1000);
      }
      function onPlaybackQualityChange(event) {
        console.log('Current quality:' + event.data);
      }
    </script>
  </body>
</body>
</html>

If you run the code you can see that onPlaybackQualityChange is only called once the video is loaded and the request to change the video quality using setPlaybackQuality() is completely ignore. Any help is appreciated. Thanks.

like image 358
user1475394 Avatar asked Jun 21 '26 19:06

user1475394


1 Answers

Unfortunately, the setPlaybackQuality() function has not been working for at least a couple of months.

For testing purposes try using setPlaybackRate() and you will find out that you can set the playback rate without any problems, but not the quality.

like image 61
Yaroslav Bershadskyy Avatar answered Jun 27 '26 16:06

Yaroslav Bershadskyy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!