Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Question Videos don't play in WebGL

Discussion in 'Audio & Video' started by Xirantics, Oct 28, 2021.

  1. Xirantics

    Xirantics

    Joined:
    Mar 13, 2021
    Posts:
    5
    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
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,476
  3. Xirantics

    Xirantics

    Joined:
    Mar 13, 2021
    Posts:
    5
    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.
     
  4. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    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.
     
  5. Xirantics

    Xirantics

    Joined:
    Mar 13, 2021
    Posts:
    5
    The URL is automatically generated. In the script I wrote
    videoPlayer.url = Path.Combine(Application.streamingAssetsPath, "video.mp4");
     
  6. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    260
    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 https://docs.unity3d.com/Manual/webgl-building.html (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
     
    Xirantics likes this.
  7. Xirantics

    Xirantics

    Joined:
    Mar 13, 2021
    Posts:
    5
    Thank you for your answer. I'll try to pay attention to all of these aspects.
     
    Last edited: Feb 21, 2022
  8. Jainnikita279

    Jainnikita279

    Joined:
    Jul 29, 2021
    Posts:
    2
    Aaronpeh022 likes this.
  9. Xirantics

    Xirantics

    Joined:
    Mar 13, 2021
    Posts:
    5
    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.