Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webgl unity build won't play Video

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.

like image 458
Jz Konain Avatar asked Feb 24 '19 20:02

Jz Konain


People also ask

How do I play video in Unity WebGL?

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.

Is Unity WebGL deprecated?

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.

Why is my Unity WebGL not loading?

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).

Does Unity WebGL still work?

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.


1 Answers

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.

like image 93
Jz Konain Avatar answered Oct 16 '22 15:10

Jz Konain