DEV Community

Piler
Piler

Posted on

[Unity] Fix video player start with black screen in Android

Solution: set the render texture initialization color to transparent.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;

public class VideoPlayerFixBlackScreen : MonoBehaviour
{
    public int width = 848;
    public int height = 480;

    public RawImage rawImage;
    VideoPlayer vp;

    void Start()
    {
        vp = GetComponent<VideoPlayer>();

        var renderTexture = new CustomRenderTexture(width, height);
        renderTexture.initializationColor = new Color(0f, 0f, 0f, 0f);
        vp.targetTexture = renderTexture;

        rawImage.texture = renderTexture;
    }
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)