Search code examples
videohttp-live-streamingvideo.jslivem3u8

How to detect video source size change?


I'm using video.js to play a live hls video (m3u8 file), but the video size changes. Is there a way to know when the video size change?


Solution

  • You probably want something like this checking for changes:

            var currentBitrate = qualityLevels[qualityLevels.selectedIndex].bitrate;
    ...snip
    
            if(currentBitrate >0){
               //see if the bitrate has changed?
               var oldBitrate = currentBitrate;
               currentBitrate = qualityLevels[qualityLevels.selectedIndex].bitrate;
               if(oldBitrate != currentBitrate){
                  //bitrate has changed, do your thing.
               }
    

    I have this running in this Github Project which is live at https://dougsillars.github.io/StreamOrNot/