videogular2 icon indicating copy to clipboard operation
videogular2 copied to clipboard

How to get networkError details while loading hls stream

Open mrtipster49 opened this issue 8 years ago • 9 comments

While loading a hls stream to the player, sometimes wowza stream returns 403. I tried subscribing to error event but it doesn't throw any event. How do I intercept network errors returned by wowza.

this.vgAPI.getDefaultMedia()
            .subscriptions
            .error
            .subscribe( (error) => {
            console.log(error);
        });

I checked out hls.js docs, it contains events for network errors https://github.com/video-dev/hls.js/blob/master/docs/API.md#fifth-step-error-handling

Based on this i tried to edit node_modules/videogular2/src/streaming/vg-hls.js and added an networkError check which seems to fire every time wowza returns an error.

// It's a HLS source
        if (this.vgHls && this.vgHls.indexOf('.m3u8') > -1 && Hls.isSupported()) {
            var video = this.ref.nativeElement;
            this.hls = new Hls(this.config);
            this.hls.loadSource(this.vgHls);
            this.hls.attachMedia(video);
            // Error Checking
            this.hls.on(Hls.Events.ERROR, function (event, data) {
                if ( data.type === 'networkError') {
                    console.log('network error encountered');
                }
            });
        }

Is there any event which handles http Error in vgAPI or how can we bind hls.js error events with videogular2 events. Sorry, if i missed out something already mentioned in the docs for this. Thanks!

mrtipster49 avatar Apr 11 '18 11:04 mrtipster49

HLS and DASH error subscriptions are dispatched from its own object, so you can't get the error from Videogular.

You can add a listener on the onPlayerReady callback:

    onPlayerReady(api: VgAPI) {
        this.api = api;
        this.vgHls.hls.on(Hls.Events.ERROR, () =>  {
            console.log('error');
        });
    }

Then set your HLS source on the ngOnInit and that's it:

    ngOnInit() {
        this.currentStream = 'https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_varian.m3u8';
    }

Elecash avatar Apr 22 '18 18:04 Elecash

@Elecash I tried window.dispatchEvent() to throw HLS network and media error from vgHLS.ts and was successful to catch those error, same as VG_Starts_Ads events, only issue with this approach was it works on all browsers but when i try to run the same code in Ionic 3 on iOS was unable to catch this event. I also tried Event Emitters, it also behaved the same. Can you please help me fix this issue on ionic too. Hopefully it could be used in videogular... Thanks.

mrtipster49 avatar Apr 22 '18 18:04 mrtipster49

I can't help you with Ionic, never worked with it before. Sorry.

Elecash avatar Apr 22 '18 18:04 Elecash

Can i share my solution with you, if its valid you may add it. It works fine on Angular 5 tested on all browsers.

mrtipster49 avatar Apr 22 '18 19:04 mrtipster49

Sure, if you want to make a PR I'm glad to review it and help you with it!

Elecash avatar Apr 22 '18 19:04 Elecash

Sorry if i up this issues,but for bypass https://github.com/videogular/videogular2/issues/726 (when there are errors in hls stream, buffer ring doesnt vanish and error in promise in console )

I try to add

@ViewChild(VgHLS) vgHls: VgHLS;


this.vgHls.hls.on(Hls.Events.ERROR, () =>  {
            console.log('error');
     }); 

but i've got

ERROR TypeError: Cannot read property 'on' of undefined
    at StreamingPlayerComponent.push../src/app/streaming-player/streaming-player.component.ts.StreamingPlayerComponent.onPlayerReady

CuriousDolphin avatar Jun 10 '18 11:06 CuriousDolphin

Sorry if i up this issues,but for bypass #726 (when there are errors in hls stream, buffer ring doesnt vanish and error in promise in console )

I try to add

@ViewChild(VgHLS) vgHls: VgHLS;


this.vgHls.hls.on(Hls.Events.ERROR, () =>  {
            console.log('error');
     }); 

but i've got

ERROR TypeError: Cannot read property 'on' of undefined
    at StreamingPlayerComponent.push../src/app/streaming-player/streaming-player.component.ts.StreamingPlayerComponent.onPlayerReady

Me too

wxcvbn612 avatar Jan 20 '19 19:01 wxcvbn612

HLS and DASH error subscriptions are dispatched from its own object, so you can't get the error from Videogular.

You can add a listener on the onPlayerReady callback:

    onPlayerReady(api: VgAPI) {
        this.api = api;
        this.vgHls.hls.on(Hls.Events.ERROR, () =>  {
            console.log('error');
        });
    }

Then set your HLS source on the ngOnInit and that's it:

    ngOnInit() {
        this.currentStream = 'https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_varian.m3u8';
    }

Please @Elecash , is there some way to get error event from hls stream?

@ViewChild('video', {read: VgHLS}) vgHls: VgHLS;
  @ViewChild('video', {read: VgMedia}) video: VgMedia;
// I TRYED 
this.vgHls; // is hls object but dont know way to subscribe on event
this.vgHls.hls // this is undefined
this.video; // media 

this.video.subscriptions.error.subscribe(()=>console.log('error')) //not working never emited

in your example is this.vgHls.hls.on but this.vgHls.hls is undefined. Please I really need event when hls stream was not loaded to show message for user - stream disabled.

FilipK23 avatar Mar 22 '19 16:03 FilipK23

I also have this problem. this.vgHls.hls is undefined.

l-hwen avatar Nov 23 '19 12:11 l-hwen