[Audio and video, chatGpt] After the h5 page is minimized, the video freezes after reactivation

Table of contents

Phenomenon

observe

 solve


Phenomenon

  Sometimes the page needs to be switched and minimized; after switching back within a short period of time or within a few hours, the video can continue normally; if left for a long time, several hours or overnight, after switching back, the video may freeze

observe

Switch page:

It is relatively normal within a few hours and will not be stuck 

 After leaving it for one night, the page freezes. Using wireshark to observe, the traffic is still there, and the video stream is also being transmitted.

According to the printing, it is found that there are several buffer groups (printing of the code after solving)

 

 solve

document.addEventListener('visibilitychange', function(){
        var bufferedTimeRanges = _SELF.video_object.buffered;

        for (var i = 0; i < bufferedTimeRanges.length; i++) {
            var start = bufferedTimeRanges.start(i);
            var end = bufferedTimeRanges.end(i);
            console.log("已缓冲时间段:" + start + " - " + end);
        }
        if (_SELF.videoBeginTime) {
          _SELF.IntervelNum = parseInt((new Date().getTime() - _SELF.videoBeginTime) / 40)
          _SELF.delayData = []
        }
        if (_SELF.pagePaused) {
          var videoBuffered = _SELF.video_object.buffered;
          console.log("videoBuffered.length",videoBuffered.length)
          if (videoBuffered.length > 0) {
            let videoEnd = videoBuffered.end(videoBuffered.length-1);
            console.log("videoEnd - _SELF.video_object.currentTime",videoEnd ,_SELF.video_object.currentTime)
            if (videoEnd - _SELF.video_object.currentTime > 0.15) {
              _SELF.video_object.currentTime = videoEnd - 0.1;
            }
          }
          var audioBuffered = _SELF.audio_object.buffered;
          if (audioBuffered.length > 0) {
            let audioEnd = audioBuffered.end(audioBuffered.length-1);
            if (audioEnd - _SELF.audio_object.currentTime > 0.15) {
              _SELF.audio_object.currentTime = audioEnd - 0.1;
            }
          }
          _SELF.pagePaused = false;
        }
      });

Guess you like

Origin blog.csdn.net/dualvencsdn/article/details/132202588