- Home /
WebGL play video using VideoPlayer and StreamingAssets
Hello everybody, I want to play video using VideoPlayer URL from StreamingAssets in my WebGL game. In editor everything works fine but when I build and upload game on my server video doesn't play. Do you have any ideas how to play video from StreamingAssets folder?
Here is script with which video play in editor:
private void StartVideo()
{
videoPlayer.url ="file://"+ Application.streamingAssetsPath + "/PlayerBadScore/1.mp4";
videoPlayer.Play();
}
Here is script with which video doesn't play in editor either server:
IEnumerator StartVideo()
{
string filePath = Application.streamingAssetsPath+ "/PlayerBadScore/1.mp4";
string result = "";
if (filePath.Contains("://")|| filePath.Contains(":///"))
{
WWW www = new WWW(filePath);
yield return www;
result = www.text;
}
else
{
result = System.IO.File.ReadAllText(filePath);
}
videoPlayer.url = result;
videoPlayer.Play();
}
And in this script I get error that .Get doesn't exists in UnityWebRequest:
var filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "/PlayerBadScore/1.mp4");
var result = "";
if (filePath.Contains("://"))
{
var www = new UnityEngine.Networking.UnityWebRequest.Get(filePath);
yield return www.SendWebRequest();
result = www.downloadHandler.text;
}
else
result = System.IO.File.ReadAllText(filePath);
videoPlayer.url=result;
videoPlayer.Play();
Answer by ilmario · Oct 19, 2017 at 07:50 AM
Tried this Unity asset yet? https://www.assetstore.unity3d.com/en/#!/content/38369 / Simple MovieTextures for Unity WebGL
Simple $$anonymous$$ovieTextures is not available on asset store. Let me know other options. I tried VideoPlayer class but doesn't work for Webgl. plz help me.
Answer by ulissescad · Apr 11, 2018 at 12:40 PM
Hehe, I have the same issue. My video play in editor but doesn't work in WebGL. Anyone please?!