I am trying to play a video using Unity’s VideoPlayer which I have attached to the camera. I want the user to be able to enter the file path of a local video file and the VideoPlayer should then play the video. I got this working fine but I can’t seem to handle exceptions when the user enters a path that is not valid, for instance:
does not print “error” but instead continues execution and gives me an error in the console saying “Can’t play movie [C:\blah]”
I can’t think of any reason why this error shouldn’t be caught by using the try catch method. I am using the latest version of Unity.
If you cannot use the try catch method to catch this exception, then I need a way to test if the url is valid and will play properly (e.g. the file is not corrupt)
@TacoMakerMan
You just need to register to the built in errorReceived event of the video player.
[In case the answer wasn’t found and for anyone else searching]
private void Start () {
loadingUI.GetComponentInChildren<Text>().text = "Loading Video
//The desired directory name of the folder that will be created in your drive
public string directoryName = "PlayerFiles";
//Path name of the file that will be in your directory
public string pathName = "playerData.txt";
//Private variables used to give the full names of their locations
string fullDirectoryName;
string fullPathName;
void Start () {
//Remember the double slashes are important in path names
//This is the full location of the directory
fullDirectoryName = "C://" + directoryName;
//This is the full location of the path/file
fullPathName = fullDirectoryName + "//" + fullPathName;
//Checks if the directory exists and if it does not then it will create it
if (!(Directory.Exists(fullDirectoryName)))
{
Directory.CreateDirectory("C://" + directoryName);
}
//Checks if the file exists and if not then it returns
if (!(File.Exists(fullPathName)))
{
Debug.Log("Video File Does Not Exist!");
return;
}
//This is the best case scenario. The file exists and will play
else
{
Debug.Log("The video is playing");
}
}