UnityPlugin-AVProVideo icon indicating copy to clipboard operation
UnityPlugin-AVProVideo copied to clipboard

WebGL: No events firing when trying to load an inactive M3U8 live stream

Open ngz82 opened this issue 3 years ago • 11 comments

Describe the issue We use a well known live streaming platform to stream videos (HLS / M3U8) into AVPro across WebGL, Android, iOS and windows. Our application allows users to configure a video URL to play in a 3d environment and normally everything works fine for both VOD and live stream except for the below case. Inactive Live Stream M3U8: When a user first enters the 3d environment , the broadcaster may not have started the streaming broadcast - in the case of our provider (who are one of the big players in this space) , the m3u8 URL they provide delivers a 403 HTTP error when the broadcaster is not actively streaming, which seems to completely break the program execution for the Media Player. Once the broadcaster starts streaming, the URL turns into a 200 with a valid m3u8 and it plays succesfully.

[AVProVideo] Initialising AVPro Video v2.4.0 (native plugin v2.1.6) on ANGLE (NVIDIA, NVIDIA GeForce RTX 3070 Laptop GPU Direct3D11 vs_5_0 ps_5_0, D3D11)/OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium)) (MT False) on WebGLPlayer
test.framework.js:2515 [AVProVideo] Opening https://dacastmmd.mmdlive.lldns.net/dacastmmd/**<randomguidhere>**/manifest.m3u8?p=79&h=**<randomguidhere>** (offset 0) with API 

We see no more logs from avpro after the above, and no errors at all.

And the network panel showing:

Request URL: https://dacastmmd.mmdlive.lldns.net/dacastmmd/**<randomguidhere>**/manifest.m3u8?p=79&h=**<randomguidhere>**
Request Method: GET
Status Code: 403 Forbidden

We have tried both putting a try /catch around the OpenMedia call as well as listening to all events and logging them, including the MediaPlayerEvent.EventType.Error: event whereby we trigger a retry mechanism periodically to see if the broadcast has started.

All of this works fine on Windows builds and in Editor - the video starts playing as expected once the broadcast goes live, triggered by the error event.

We are logging on every event as mentioned

private void VideoEventHandler(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
        {
            Debug.Log($"Video Media Panel: State: {et.ToString()}");
            switch (et)

and yet there are no events firing at all, it's as though it just stops execution. There are no other logs of note in the developer console.

If the broadcaster is streaming when the video player first loads, everything works as expected on all platforms. The retry mechanism we implemented which fires off the error event and also if any exception occurs around the OpenMedia call works fine on other platforms, just not webgl.

We could possibly add a coroutine/timer to periodically check if a video should be playing and if it should retry, but it seems like a bug if there are no events firing at all and no errors/exceptions occurring, e.g an error event or something else we can hook into to trigger a modal or retry mechanism. It's as thought 403 HTTP error never makes its way to trigger an error back to the media player.

Your Setup (please complete the following information):

  • Unity version: 2021.3.5f1
  • AVPro Video version (number and edition (trial/core/ultra/enterprise)): 2.4.0 Core
  • Operating system version: Windows 10
  • Device model: Windows 10, Chrome Browser Version 104.0.5112.102 (Official Build) (64-bit)
  • Video specs (resolution, frame-rate, codec, file size): 720p/480p/, HLS , M3u8 Bitrate - Resolution 0.33 180x320 0.73 360x640 1.13 480x848 1.93 576x1024 2.59 720x1280

To Reproduce

  1. WebGL project with a video player, using the hls.js library,
  2. try to open a live stream .m3u8 that doesn't exist (i.e put any m3u8 url in that will return a 403 error)

Logs If applicable, add error logs to help explain your problem.

Screenshots If applicable, add screenshots to help explain your problem.

Videos If applicable, add a copy of your video or the URL

Please DO NOT LINK / ATTACH YOUR PROJECT FILES HERE

Instead email the link to us [email protected]

ngz82 avatar Sep 01 '22 12:09 ngz82

Hi, We don't officially support WebGL.
If the stream becomes active, does it start playing? Have you tried it in different browsers?

Chris-RH avatar Sep 02 '22 12:09 Chris-RH

I've conducted further testing. I was able to work around one of the scenarios , i.e. if a user enters the 3d environment prior to the live stream commencing by using some timers to retry, this solves one of the biggest issues (users entering before a live stream starts and it remaining broken forever), however now that the stream begins - I simulated the connection being dropped by stopping the live stream, after a few moments I start seeing the 403 server errors from the streaming server in the browser developer tools. It looks to me as though AVPro retries 5 times before giving up (see the screenshot). Unfortunately the only events we can tap into here are StartedBuffering and FinishedBuffering which are common/standard events so we would not want to use these to affect the application flow. We attempted to check mediaPlayer.Control.IsPlaying() to see if media was playing and if not , after a period of time to call stop() and re-enable the retry mechanism however when checking mediaPlayer.Control.IsPlaying() it is returning true even whilst these errors are happening. After the 5 attempts nothing further happens.

Please advise if you have any other suggestions for us to detect when a stream is completely stopped. I considered maybe comparing the textures being received and if they have not changed in a period if time we could call the Stop() and recommence the reconnect logic. I've not tried this but let me know if you think it could work or alternatively any other quick fix/solutions I can try for the above.

ngz82 avatar Sep 02 '22 12:09 ngz82

image

ngz82 avatar Sep 02 '22 12:09 ngz82

P.s thanks I acknowledge and understand you don't officially support WebGL so I'm just asking for some direction - happy to try workaround/fix things ourselves. FWIW, I believe WebGL is only going to get more and more prevalent and performant over time - it will become a widely supported platform due to its portability. Thanks for keeping the WebGL libraries in the package!

ngz82 avatar Sep 02 '22 13:09 ngz82

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 20 '22 19:09 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 01 '22 16:10 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 15 '22 18:10 stale[bot]

Is there a way to tell if an M3U8 live stream changes state from inactive to active during play mode and without using timers to manually check? Thank you.

massimilianogaio avatar Mar 24 '23 11:03 massimilianogaio

Have you tried checking for stalled/unstalled events?

Chris-RH avatar Mar 24 '23 13:03 Chris-RH

Thanks for the reply. If I initialize a MediaPlayer with a M3U8 url that is not active yet, a stalled event is raised. But when livestreaming is activated, no events are raised, so you still don't see any content. If I call the OpenMedia() once again, the video stream starts to be seen correctly.

massimilianogaio avatar Mar 24 '23 14:03 massimilianogaio

Have you tried checking for stalled/unstalled events?

Hi, I used stalled/unstalled events correctly for a month but for a few days now if I try to use a non-active link, I no longer receive any events in webGL and Android Builds. From Editor, however, it works. Can you give me some info about it?

massimilianogaio avatar Apr 18 '23 11:04 massimilianogaio