Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality. If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers. And always feel free to hit us up on Twitter @MxdRealityDev.

Unity VideoPlayer - IsPrepared() … is never prepared

Good morning,

I was trying to create a method of a class where it retrieves a video data from a www URL and then displays it with a defined position and size by clicking a button in Unity. The idea is to use part of this code for an Hololens app.

However, when I start the process the video doesn't work nor do anything. After analyzing the code I noticed that the IsPrepared() method is never-ending, it gets stuck there forever. I attached my code right beneath this comment.

public IEnumerator CreateVideo(WWW www, RawImage image)
{
Debug.Log("Video");
yield return www;
//Set Size & Position
image.GetComponent().sizeDelta = new Vector2(0.5f, 0.5f);
image.GetComponent().position = new Vector3(0.5f, 0.5f, 10.0f);

    //Add VideoPlayer to the GameObject
    //videoPlayer = image.GetComponent<VideoPlayer>();

    //Add AudioSource
    // audioSource = image.GetComponent<AudioSource>();

    //Add VideoPlayer to the GameObject
    VideoPlayer videoPlayer = image.GetComponent<VideoPlayer>();

    //Add AudioSource
   AudioSource audioSource = image.GetComponent<AudioSource>();
    Debug.Log(audioSource);
    //Disable Play on Awake for both Video and Audio
    videoPlayer.playOnAwake = true;
    audioSource.playOnAwake = true;



    //We want to play from url
    videoPlayer.source = VideoSource.Url;
    videoPlayer.url = www.url;


    //Set Audio Output to AudioSource
    videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
    videoPlayer.controlledAudioTrackCount = 1;

    //Assign the Audio from Video to AudioSource to be played
    videoPlayer.EnableAudioTrack(0, true);
    videoPlayer.SetTargetAudioSource(0, audioSource);

    //Set video To Play then prepare Audio to prevent Buffering
    videoPlayer.Prepare();

    WaitForSeconds waitTime = new WaitForSeconds(5);
    while (!videoPlayer.isPrepared)
    {
        Debug.Log("Preparing Video");
        //Prepare/Wait for 5 sceonds only
        yield return waitTime;
        //Break out of the while loop after 5 seconds wait
        break;
    }

    //Assign the Texture from Video to RawImage to be displayed
    image.texture = videoPlayer.texture;

    //Play Video
    videoPlayer.Play();
    Debug.Log("Playing Video");

    //Play Sound
    try
    {
        audioSource.Play();

    }catch (System.Exception e)
    {
        Debug.Log(string.Format("Exception thrown whilst getting audio clip {0} ", e.Message));
    }




    while (videoPlayer.isPlaying)
    {
        Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)videoPlayer.time));
        yield return null;
    }

    Debug.Log("Done Playing Video");
}

The RawImage Object is saved in the Prefab folder (in the future I want to instantiate the object), where I included several components as VideoPlayer, AudioSource, Mesh Renderer (in case it is needed) and a Transparent texture.

Any idea of the possible solution of this issue?

Thanks in advance!

Tagged:
Sign In or Register to comment.