3
votes

I'm new to Unity and am trying to update a VideoPlayer via my script. I have confirmed the code is working with a preset value but when I run videoPlayer.url = "new video url" it will not play.

Here is my code for playing videos. This will work but once I give it a url to update to, it just changes the source but does not play the video.

public IEnumerator playVideo(string videoYear) {
        // This line updates the url but the video will not actually play.
        videoPlayer.url = "example.com/app/" + videoYear + ".mp4";

            videoPlayer.Prepare();
            WaitForSeconds waitForSeconds = new WaitForSeconds(1);

            while(!videoPlayer.isPrepared) 
            {
                yield return waitForSeconds;
                break;
            }

            rawImage.texture = videoPlayer.texture;
            videoPlayer.Play();
    }
1
Are there any errors in console?Nitro557
Have you tried putting "http://" in front of the URL? The example in the documentation uses that (docs.unity3d.com/ScriptReference/Video.VideoPlayer.html)Nicklas C.
@Nitro557 No console errors.Joe Scotto
@NicklasC. Yes, in my actual code it has http://Joe Scotto
@JoeScotto , ok. And what if videoPlayer.url = "http://actual_video_url_without_combining"?Nitro557

1 Answers

0
votes

This method is being run from a co-routine correct? You also mentioned that in debug mode the URL is not even being set to the value?

actions: Run the exact same code without using the co-routine, and check if the problem occurs when passing in a static url value to a deterministic method. (i.e. without using a co-coroutine). If this works then examine the code that is calling your co-routine, and consider adding that to your question, to demonstrate the call flow.

I'm speculating that the code sample of the problem is simplified. As quesiton comments mention the problem exists outside of your code sample.

Do you use a second co-routine for retrieving the url to the video source file first? If you are try isolating this first by passing a constant url to the co-routine that starts the videoplayer. If this works then add a second yield statement for the first co-routine so that you are waiting for both the url value to be ready as well as the preparation of the video player object loading the video source.