VideoPlayer sometimes crashes the game in specific android devices

We have added a tutorial in our game using looping video playback. The problem is that on the Android build on some devices the game sometimes crashes after a few seconds of playing the video. The video player output goes to the raw texture. This texture is used by the UI Image, and the GifPlayer script operates on these processes. All screenshots are below

public class GifPlayer : MonoBehaviour
{
    public static GifPlayer Instance { get; private set; }

    [SerializeField] private GameObject rawImage;
    [SerializeField] private VideoPlayer videoPlayer;

    private void Awake()
    {
        Instance = this;
        rawImage.SetActive(false);
    }

    public void StartVideo(VideoClip clip)
    {
        StartCoroutine(PrepareVideo(clip));
    }

    private IEnumerator PrepareVideo(VideoClip clip)
    {
        videoPlayer.Stop();
        videoPlayer.clip = clip;
        videoPlayer.Prepare();

        while (!videoPlayer.isPrepared)
        {
            yield return new WaitForSeconds(Time.fixedDeltaTime);
        }

        videoPlayer.Play();
        rawImage.SetActive(true);
    }

    public void StopVideo()
    {
        rawImage.SetActive(false);
        videoPlayer.Stop();
    }
}

I would start with the runtime device logging (usually via adb logcat) and see if there are any obvious errors to fix.

Video is easily one of the most finicky things to get right, between different codecs and bitrates and whatnot. Start with a blank project that only plays your video and nothing else. If you can’t get that working well, no sense in tearing up your actual game to chase ghosts that you cannot fix.

1 Like

Which Unity version are you using?

We use 2022.3.24f1 version