Search Unity

How to Download the Video and Play

Discussion in 'Scripting' started by Alexander21, Jun 17, 2019.

  1. Alexander21


    Dec 14, 2015
    Hi All

    I have a video in dropbox. and i then i have to download the video from dropbox. and then i have to play the video. I am using unity 2018. How can i play the video?

    I know there is a video player option is there. But i dont want any live streaming. It should fully downloaded from drop box . and then it get stored. and then i have to play.

    Thanks in advance.
  2. Kwinten


    Jan 25, 2015
    You would need to use the WWW class to fetch and download the video from DropBox.
    Then you need to store the video file on your storage somewhere - the persistent data folder should work. The VideoPlayer cannot play videos stored in memory - it needs to be on disk or from a URL.
    Then you can set the VideoPlayer's url to the file path of where you stored the video on disk (using the VideoPlayer.url property).

    If something's not clear, I can try to explain in more detail.
  3. csofranz


    Apr 29, 2017
    Yup, as Kwintern said.

    Here's how to download a file with Unity using WebRequest

    Here's how you can save a file just requested to disk at a path
    Code (CSharp):
    1. IEnumerator GetText(string file_name)
    2. {
    3.     string url = "" + file_name + ".pdb";
    4.     using (UnityWebRequest www = UnityWebRequest.Get(url))
    5.     {
    6.         yield return www.Send();
    7.         if (www.isNetworkError || www.isHttpError)
    8.         {
    9.             Debug.Log(www.error);
    10.         }
    11.         else
    12.         {
    13.             string savePath = string.Format("{0}/{1}.pdb", Application.persistentDataPath, file_name);      
    14.             System.IO.File.WriteAllText(savePath, www.downloadHandler.text);
    15.         }
    16.     }
    17. }

    Here's how to play a file once you saved it to a path
    Kwinten likes this.