I have used video player to play video, everything works fine in unity but when I build it and run on firefox or any other browser,the video won't play. I have tried different settings and different video formats but nothing seems to work. I don't get any errors.
I have an empty scene with camera and video player, no scripts. Just used video player and used play on awake to play the video. Works fine in playmode but won't work in webgl build.
Unity WebGL doesn't support playing video directly from assets! You can either place your video under StreamingAssets path or external file server, then you can provide the video URL as the source. Even then you would need to take care of following: CORS in case of external file server.
In version 2021.2, Unity marked support for the WebGL 1 Graphics API as deprecated. In Unity 2021.2, there are no changes in behavior and Unity still includes the WebGL 1 Graphics API if you enable the Auto Graphics API Player Setting.
WebGL does require some web knowledge to get it ticking. First, disable the compression in the playersettings. Enabling compression requires your webserver to serve your content correctly, since you do not have a webserver running, it doesn't even serve it. Second: Try to do a build and run (Ctrl + B).
It may still work, especially on high-end devices, but many current devices are not powerful enough and don't have enough memory to support Unity WebGL content well.
In the editor create a folder with the name StreamingAssets and put your video files into that folder. The video format that I used is mp4 . Create a VideoPlayer component and attach it to a gameobject. Reference that component in a script and use the following command
videoPlayer.url = System.IO.Path.Combine (Application.streamingAssetsPath,"myFile.mp4");
You can use other videoplayer commands like Video.Play();
to play the video.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With