videojs / video.js

Video.js - open source HTML5 video player
https://videojs.com
Other
37.96k stars 7.44k forks source link

Handling ngrp Protocol for Fallback Scenarios in Video.js #8269

Open StavrosNik4 opened 1 year ago

StavrosNik4 commented 1 year ago

Description

In our current implementation, we have an array of 3 sources (2 livestreams from different Wowza streaming engines and 1 VOD message) to handle fallback scenarios. If the first live source is not available, the second one is played. If both live sources are down, the VOD message is played to inform users that the livestream is not up yet. This setup works well with .stream files, but we're facing issues when using .stream_all files with the ngrp protocol to get multiple stream qualities.

The current code snippet is as follows:

let player = videojs('my-video', options);

var currentIndex = 0;

player.src(sources[currentIndex]);

player.on('error', function() {
    if (currentIndex < sources.length - 1) {
        currentIndex++;
        player.src(sources[currentIndex]);
    } else {
        // handle error when all sources fail
        console.log('All sources failed');
    }
});

For .stream files, the error event is triggered with an error code of 4 if the stream is not up, and the fallback works as expected. However, when using ngrp, a warning is produced instead: VIDEOJS: WARN: Problem encountered with playlist 0-https://example.com/ScheduleRecording/ngrp:test.stream_all/playlist.m3u8. Trying again since it is the only playlist. As a result, the error event is not triggered, and the fallback mechanism doesn't work.

We attempted to modify the source code to produce an error instead of a warning, but the error callback still fails to recognize it.

We're seeking guidance on how to handle this issue with ngrp protocol and ensure the fallback mechanism works as expected.

Reduced test case

https://codepen.io/StavrosNik4/pen/PoyRKmm

Steps to reproduce

  1. Just run the Codepen

Errors

image

What version of Video.js are you using?

7.11.4

Video.js plugins used.

No response

What browser(s) including version(s) does this occur with?

Chrome, Firefox

What OS(es) and version(s) does this occur with?

Windows 10

video-archivist-bot commented 1 year ago

Hey! We've detected some video files in a comment on this issue. If you'd like to permanently archive these videos and tie them to this project, a maintainer of the project can reply to this issue with the following commands:

welcome[bot] commented 1 year ago

👋 Thanks for opening your first issue here! 👋

If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

amtins commented 1 year ago

@StavrosNik4 the naive solution

player.on(['error', 'play'], function() {
    if (currentIndex < sources.length - 1 || !player.buffered().end(0)) {
        currentIndex++;
        player.src(sources[currentIndex]);
        player.play();
    } else {
        // handle error when all sources fail
        console.log('All sources failed');
    }
});
StavrosNik4 commented 1 year ago

@amtins

@StavrosNik4 the naive solution

player.on(['error', 'play'], function() {
    if (currentIndex < sources.length - 1 || !player.buffered().end(0)) {
        currentIndex++;
        player.src(sources[currentIndex]);
        player.play();
    } else {
        // handle error when all sources fail
        console.log('All sources failed');
    }
});

That goes immediately to the VOD message even though the 2nd stream is up and the 1st one is not. Maybe you meant something different? Or can you explain your thought process?