Unity/Videoplayer - Game sometimes crash if I load next video

Viewed 1101

I use Video Player which attached 3D game object. This game object contain "Mesh Renderer" component too. Video Player Renderer-> this game object. I try many method, but always crash game.

  1. I try use in Update: Videoplayer().isplaying if false, then I load from Resources next video and play, but not working. (Unity Editor working fine, but in iPhone sometimes crash game.)

  2. Then I try other method.. But sometimes crash too.. Okey, I think maybe loading and start playing too fast, maybe this cause the crash. Then I try use Ienumerator waitforsecond every step, for debugging I set it 5 seconds. I try first set video player.clip = null, maybe this is the problem.. But not..

Now the code:

void Start()
{
    index = 0;
    videoPlayer = gameObject.GetComponent<VideoPlayer>();
     videoPlayer.loopPointReached += CheckOver;
}
IEnumerator Waitforseconds()
{
    Debug.Log("Waitforseconds start");
    videoPlayer.clip = null;
    Debug.Log("Videoplayer clip null);
    yield return new WaitForSeconds(5);
    videoPlayer.clip = theVideo;
    Debug.Log("Videoplayer set the video");
    yield return new WaitForSeconds(5);
    Debug.Log("Next play video player");
    videoPlayer.Play();
    Debug.Log("Play video player");
    isPlaying = true;
}
   void CheckOver(UnityEngine.Video.VideoPlayer vp)
    {
        Debug.Log("Checkover");
        index += 1;
        if (index >= videos.Length)
        {
            index = 0;
        }
        theVideo = videos[index];
        Debug.Log("Set the video");
        StartCoroutine(Waitforseconds());     
    }

The videos size 5-10 MB and 10-60 seconds. The result: Unity Editor working good, I build to iOS and sometimes crash the game if I play next video (iPhone 12 Pro Max, supposedly the fastest smartphone chip, so if that doesn't work, there's a big problem..)

Debug: I get last Debug.log before the game crash: "Videoplayer clip null" So I think the game crash here: videoPlayer.clip = theVideo; But only iOS! Unity editor working good.

Xcode error: enter image description here

I try find solution in google, but I can't find.. Maybe memory error? should I somehow delete the previous video from memory? Or how can I solve this problem? Please help me.

Thank you very much!

EDIT: I see the problem is Audio. (Audio Output mode: Audio Source, this component attached to same gameobject. So same game object contain audio source and video player.) If I set Audio Output mode to "none", then game not crash, workin good. So the problem when "PrepareAudioTap". How can I solve this problem?

1 Answers

Solved!

I change Video Player component "Audio Output mode": Audio Source to Direct. Then not crash game.

But I would like to use Audio Source, because I need 3D Sound. (not important, I'm glad it works, but if you have idea how to work with 3D sound, I would be glad.)

Thanks!

Related