Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

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.

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, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

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.