Rather than dragging an existing Video Clip asset file to specify which video to play, VideoPlayer can also download video clips from an online source. To do this, we need to assign a string URL to the video player's URL property.
To download a video, do the following:
- Declare a public array of strings, in which one or more URLs can be defined:
public string[] urls = {
"http://mirrors.standaloneinstaller.com/video-sample/grb_2.mov",
"http://mirrors.standaloneinstaller.com/video-sample/lion-sample.mov"
};
- Declare a new method that returns one URL string, randomly chosen from the array:
public string RandomUrl(string[] urls)
{
int index = Random.Range(0, urls.Length);
return urls[index];
}
- Finally, in the SetupVideoAudioPlayers() method, we need to get the random URL string and assign it to the video player's url property:
private...