I am trying to get a video from my 'Json' file which I upload it on azure server to Raw image component in unity but it looks like That : enter image description here
to get a picture it works well but for video mp4 it doesn't, this is the Code :
using UnityEngine ;
using UnityEngine.Networking ;
using UnityEngine.UI ;
using System.Collections ;
// Json data format
/*
{
"Name" : "..." ,
"VideoURL" : "..."
}
*/
public struct Data {
public string Name ;
public string VideoURL ;
}
public class Demo : MonoBehaviour {
[SerializeField] Text uiNameText ;
[SerializeField] RawImage uiRawImage ;
string jsonURL = "https://myserver..." ;
void Start () {
StartCoroutine (GetData (jsonURL)) ;
}
IEnumerator GetData (string url) {
UnityWebRequest request = UnityWebRequest.Get (url) ;
yield return request.SendWebRequest() ;
if (request.isNetworkError || request.isHttpError) {
// error ...
} else {
// success...
Data data = JsonUtility.FromJson<Data> (request.downloadHandler.text) ;
// print data in UI
uiNameText.text = data.Name ;
// Load video:
StartCoroutine (GetVideo (data.VideoURL)) ;
}
// Clean up any resources it is using.
request.Dispose () ;
}
IEnumerator GetVideo (string url) {
UnityWebRequest request = UnityWebRequest.GetTexture (url) ;
yield return request.SendWebRequest() ;
if (request.isNetworkError || request.isHttpError) {
// error ...
} else {
//success...
uiRawImage.texture = ((DownloadHandlerTexture)request.downloadHandler).texture ;
}
// Clean up any resources it is using.
request.Dispose () ;
}
}
So this Code load well an Image to my unity but for video it doesn't, I tried to get all type of videos that unity support but same thing. so to Raw Image component I add video player component which i add a render texture to it and to image raw but also same thing. my unity version is 2019.4.26f1. it can be because of unity's version? I hope someone can help me really.