Code Monkey home page Code Monkey logo

Comments (9)

flavioribeiro avatar flavioribeiro commented on May 9, 2024

It seems that clappr is not handling rebuffering events after the first one on html5 playback. Since we don't have events like flash's BUFFERING and BUFFER_FULL , I think that the best approach is to follow currentTime and buffered.end() values and figure out a good heuristics to define if the playback is stuck or not.

from clappr.

towerz avatar towerz commented on May 9, 2024

@flavioribeiro Are you testing the html5 playback with a mp4 or m3u8? Can you share the URL you are using for the tests?

It's possible that the stalled/waiting events are being discarded due to the readyState informing that the player has future data available. It could either be a bug on the html5 playback or a weird browser behavior.

from clappr.

flavioribeiro avatar flavioribeiro commented on May 9, 2024

yes, I'm trying with mp4 and the main problem is indeed with media api (video tag behavior). I'm gonna try to suggest something here in a pr.

from clappr.

towerz avatar towerz commented on May 9, 2024

@flavioribeiro Seems to be a bug on Chrome and other Chrome based browsers. Other browsers such as Safari and Firefox trigger the stalled and waiting events normally. Analyzing further, Chrome apparently doesn't set the element readyState correctly as well. It really looks like we can't work around it.

from clappr.

flavioribeiro avatar flavioribeiro commented on May 9, 2024

indeed there's an old bug (2011) which was not solved yet. I found this stackoverflow thread also. I think that a "good" workaround is to look if currentTime >= buffered.end(buffered.length -1) and if so, dispatch the buffering event. We could check it every timeupdate or progress event, for example. What do u think about it?

from clappr.

towerz avatar towerz commented on May 9, 2024

I think it could work well. I'd rather use the progress event to track this, only to be sure it will be called whenever there's change on network activity.
Using timeupdate might break more easily if it stops being called whenever data is not ready on the buffer.

from clappr.

flavioribeiro avatar flavioribeiro commented on May 9, 2024

something like this might work. I made some tests using charles and it worked fine, however there's some entropy on the numbers reported when the bandwidth is floating right in the same rate of the video (there's some cases where the browser says it has 3 seconds of buffered video but it keeps stuck). To summarize, this snippet should solve 90% of the cases.

diff --git src/playbacks/html5_video/html5_video.js src/playbacks/html5_video/html5_video.js
index 4424ecb..e47affe 100644
--- src/playbacks/html5_video/html5_video.js
+++ src/playbacks/html5_video/html5_video.js
@@ -198,9 +198,20 @@ class HTML5Video extends Playback {
         break
       }
     }
+    this.checkPlaybackState()
     this.trigger(Events.PLAYBACK_PROGRESS, this.el.buffered.start(bufferedPos), this.el.buffered.end(bufferedPos), this.el.duration, this.name)
   }

+  checkPlaybackState() {
+    if (this.el.currentTime >= this.el.buffered.end(this.el.buffered.length - 1)) {
+      this.trigger(Events.PLAYBACK_BUFFERING, this.name)
+      this.buffering = true
+    } else if (this.buffering === true) {
+      this.trigger(Events.PLAYBACK_BUFFERFULL, this.name)
+      this.buffering = false
+    }
+  }
+
   typeFor(src) {
     return (src.indexOf('.m3u8') > 0) ? 'application/vnd.apple.mpegurl' : 'video/mp4'
   }

from clappr.

towerz avatar towerz commented on May 9, 2024

Maybe instead of checking this.el.buffered.length -1, you should use bufferedPos. If the user seeks back to a unbuffered position and the player stalls, checkPlaybackState() would not set the buffering state correctly.

from clappr.

flavioribeiro avatar flavioribeiro commented on May 9, 2024

yes, you are right! I'm gonna change this and submit a pull request.

from clappr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.