Hello, I’m trying to use the new VideoPlayer class to play a video file on my android device, unfortunately I’m getting a NullReferenceException:
NullReferenceException: Object reference not set to an instance of an object
at VideoPlayerUI.SetVideoURL (System.String url) [0x00000] in :0
This is my code in VideoPlayerUI.cs
public void SetVideoURL(string url)
{
_videoPlayer.source = VideoSource.Url;
_videoPlayer.url = url;
}
I made sure the url that is being passed is valid, it looks like this: “/storage/emulated/0/Android/data/com.company.project/files/myVideo.mp4”
I’ve also tried adding “file://” to the start of the url and still the same result.
I then tried to build the project with that same path already set on the videoplayer object, then it would work (although the video is choppy when it plays) but I still need to set the video url during runtime, which isn’t working.
when I try this code in the editor with a video file on my desktop it works and I don’t get the null reference exception.
I’m not sure what I’m missing here, any help is very appreciated, thanks!
One last question, is there a way to import videos into VideoClip assets during runtime?
Android device: Samsung S4
Unity version: 2017.1.0b9