videojs / videojs-contrib-ads

A Tool for Building Video.js Ad Plugins
http://videojs.github.io/videojs-contrib-ads/
Other
381 stars 257 forks source link

Exception when HLS/DASH chunks are requested before the ad returns from the broker #499

Open nepomucenobr opened 5 years ago

nepomucenobr commented 5 years ago

Description

I wrote a proof of concept FreeWheel plugin and it works fine for progressive streams. However, it fails when I use HLS/DASH (I see an error on the console and when the ad finishes, the regular video won’t play). I noticed it happens when the ad broker takes a bit of time to return something. I tested it with two ad servers, one that returns a fake ad right away and another one that goes through the bidding process with lots of fallbacks and all. It works fine for the first one, but fails for the second. Looking at the network tab, I noticed it fails when the player starts requesting the video chunks before the ad comes back from the broker (it works perfectly, otherwise). Apparently what’s happening is the player starts requesting the HLS/DASH video chunks and when it gets the ad, the video source is changed. Then, when the chunks arrive, the player says: “oh wait, I don’t know what to do with these anymore, I am playing something else now”. I am not sure if this is a bug with the videojs-contrib-ads plugin or if I should be calling something I am not.

Below you will find some information about how I am handling/triggering the main events associated with ad playback.

onRequestComplete = function(evt) {
  if (evt.success) {
    // (...)
    if (temporalSlots.length && player.fw.prerollSlots.length) {
      player.trigger("adsready");
    }
    else {
      player.trigger("nopreroll");
    }
  }
},
playAd = function() {
  if (player.fw.prerollSlots.length) {
    player.ads.startLinearAdMode();
    state.adPlaying = true;

    player.trigger('ads-ad-started'); //  I also tried placing this after the slot.play(), but it didn't work either

    var slot = player.fw.prerollSlots.shift();
    slot.play();
  }
  else {
    player.trigger('ads-ad-ended');
    player.ads.endLinearAdMode();
    state.adPlaying = false;
  }
}

Here is the actual error I am getting: Uncaught DOMException: Failed to read the ‘buffered’ property from ‘SourceBuffer’: This SourceBuffer has been removed from the parent media source.

hls_ad_issue_error

Versions

videojs-contrib-ads version: 6.6.4 Video-js version: Video.js 7.6.0 Other plugins:

Platforms

Browsers: Chrome 76.0.3809.132 and Microsoft Edge 44.17763.1.0 (Microsoft EdgeHTML 18.17763) OS/Devices: Windows 10

AdamTyler commented 4 years ago

@nepomucenobr Any progress on this? I'm having the same issue. Also trying to use freewheel