Search Unity

Video When is video player finished loading from url?

Discussion in 'Audio & Video' started by apalasthy, Jul 8, 2020.

  1. apalasthy

    apalasthy

    Joined:
    Nov 13, 2019
    Posts:
    8
    I'm working on a video streaming project and need to implement a system to preload videos to play them smoothly one after another.

    I made a list of video players, supply each with a url and set them to Prepare().

    I've noticed that they draw bandwidth even after getting onPrepared callback.
    That wouldn't be such an issue, but I need to know when is a video player done downloading data so that I can start playing.

    Otherwise the currently playing video will be starved of bandwidth.

    tl;dr: How do I know that video player finished downloading data from url? OR How can I pause this download?
     
  2. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    260
    Hi!

    The VideoPlayer doesn't currently expose the preload status of the video. The prepareCompleted event (which can also be polled using the isPrepared property) is your only signal. But this typically tells you that a number of frames are ready to be played, and not that the playback is guaranteed to be smooth, or that the download is completed.

    The reason why bandwidth is used even after preparation is completed is that we don't download the whole movie before playback. This method is called progressive download and aims at offering an earlier start than completely downloading the movie ahead of time. One notable exception to this is how the webm format is currently implemented on most platforms (Android being one exception): this does a full download ahead of time. But it does so in memory so make sure you take this into account if you prepare multiple webm videos.

    This mechanism clearly does not cover all possible use cases, so if you prefer to download all the files locally prior to playback, then you can do so using UnityWebRequest. Make sure to set the request's downloadHandler to a DownloadHandlerFile.

    Once the file is finished downloading, you can play it from the local filesystem since VideoPlayer.url supports local file paths as well as file:// urls.

    Hope this helps,

    Dominique Leroux
    A/V developer at Unity
     
    xeniaeo likes this.
  3. apalasthy

    apalasthy

    Joined:
    Nov 13, 2019
    Posts:
    8
    Unfortunately, this feature was mandatory for my project so I went ahead with the avPro plugin.
    But it's good to have this confirmed.
    Thank you for the response.