0

[EDITED] I'm preparing an application for OculusGo = Android In the scene there's 4 characters represented by video clips. Video size between 10mb - 30 mb each.

All video are with the shader GoogleVR/Unlit/TransparentOverlay The videos were encoded to WebM/ VP9/ keep alpha with Adobe encoder. The videos further transcoded in unity to Android, VP8 (again).

The videos loaded from a resources folder at the begining of the scene, and then when it's time to play them VideoPlayer.Play() is called from each one of them and finally they all play together. (Start one after another and continue together).

The issue is: My app is crashing when the third video is supposed to play. It doesn't crash when I "prepare" the video, but only on "VideoPlayer.Play()"

Here's my current code:

public float waiting;
public AudioSource characterAudio;

VideoPlayer videoPlayer;
bool videoStarted = true;

void Awake () {
    
    videoPlayer = GetComponent<VideoPlayer>();
}

private void Update()
{
    if (characterAudio != null)
    {
        if (characterAudio.isPlaying && videoStarted)
        {
            StartCoroutine(StartVideo());
            videoStarted = false; 
            Debug.Log(characterAudio.name + " called once from update");
        }
    }
}

IEnumerator StartVideo()
{
    yield return new WaitForSeconds(waiting);
    videoPlayer.enabled = true;
    videoPlayer.Prepare();
    while(!videoPlayer.isPrepared)
    {
        Debug.Log("video is preparing");
        yield return null;
    }

    videoPlayer.Play();
    Debug.Log("videoStarted, char name is: " + characterAudio.name);
}

This is the errors I get from logcat (using command: logcat |grep -i unity)

ActivityManager: Force removing ActivityRecord

Consumer closed input channel or an error occurred. events=0x9

Channel is unrecoverably broken and will be disposed!

InputDispatcher: Attempted to unregister already unregistered input channel

Please help, I've been trying for two weeks to get these videos to run simultaneously.

Also I read about using different thread here: https://gamedev.stackexchange.com/questions/113096/how-to-not-freeze-the-main-thread-in-unity and about videos playing simultaneously here: Unity App freezes when loading Multiple Videos on same Scene

I ran logcat (not unity one), and this is what I got right after video preparation has ended:

Screenshot from terminal

4

1 回答 1

0

我解决这个问题的方法是通过以下步骤:

  1. 我没有同时播放 4 个不同的视频并使用四个视频的内存,而是使用了一个视频 - 除以 4 - 每个角色在一个可以运行的视频上都有一个“插槽”。
  2. 我使用了一种材料 - 而不是使用 4 种材料,一种材料来播放视频。此材质显示所有 4 个角色的视频,因此为了正确显示角色,我偏移了材质渲染纹理 x、y 位置和偏移量,因此场景中的四个不同位置仅显示一个角色。

所以总结一下,我没有加载和播放具有四种​​不同材料的 4 个视频并在系统上造成过载,而是在 1 个材料上播放了 1 个视频。应用程序运行顺利。

于 2022-02-21T09:46:00.050 回答