Videos don't play in WebGL

Hello, I’ve uploaded a WebGL game build to Unity Play that contains a video starting after the player presses the spacebar. After using “Build and Run” in the editor the video played perfectly in the localhost server.
I put the video in the StreamingAsset folder and used the url reference to the video in the script.
What can I do to solve the problem?

Thank you

check Browser console for errors? (F12 key in most browsers)

also,

you could upload the video on the server manually, and use that URL.

Hello, thank you for your reply.
I read the documentation, but I get this error: HTTP/2 404 Not Found 235ms.
And the error says that it is not possible to complete the upload of the resource https://play.unity3dusercontent.com/webgl/StreamingAssets/video.mp4

The folder StreamingAssets that contains video.mp4 is in Assets folder.

Its probably an authentication issue. The URL you list I cannot access either. It probably works for you normally because you are authenticated via the web browser. Try accessing the URL from an incognito window to make sure it is public.

The URL is automatically generated. In the script I wrote
videoPlayer.url = Path.Combine(Application.streamingAssetsPath, “video.mp4”);

1 Like

Hi Xirantics!

Not sure exactly what is at play here, but like others have pointed out, do make sure that the resulting url that comes from your call to Path.Combine points to a path that exists and is accessible. Also pay attention to the WebGL-specific note in https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html (where it specifically says that files are not accessible in the normal way on WebGL). So it’s plausible that the file is simply not where you think it is.

Another thing to keep in mind is the CORS (Cross-Origin Resource Sharing) setup, in case the video file you’re playing ends up being on a different server than the rest of the game. You can read about CORS in Unity - Manual: Build your WebGL application (in the section about Moving build output files), as well as in the WebGL networking page.

Hope this helps,

Dominique Leroux
A/V developer at Unity

1 Like

Thank you for your answer. I’ll try to pay attention to all of these aspects.

Hey!
Could you find a solution to this? I am facing exactly same issue. My similar autogenerated URL (using same script) is giving 404. I am unable to find a solution to this.

1 Like

Hello, the video I was trying to link was created with Cinemachine directly inside Unity. So, instead of saving it and trying to load it from somewhere, I simply let it play from the dedicated scene. You can do it for example by adding a start button that - when clicked - switches from the menu to the video scene.