untiy AVProVideo judges whether the video is loaded and can be played

My plugin version is 5.3, the API may be different in different versions

If you jump to the video as soon as it is opened, the jump will fail because the video is not loaded, so you must wait for the video to load before jumping. You can wait for a while before jumping, but if the waiting time is fixed, one is The loading time of each video is different and cannot be precisely controlled, but the user experience is not good due to the obvious loading delay.

You can use the plug-in's event system to determine whether it has been loaded, and when it is ready to play, the plug-in will send an event

private bool isReady;//视频是否已经准备好
private MediaPlayer MediaPlayer;//视频播放器

private void Start()
{
    
    
 	MediaPlayer.Events.AddListener(OnVideoEvent);//注册事件
}

 public void OnVideoEvent(MediaPlayer mymp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
        {
    
    
            switch (et)
            {
    
    
                case MediaPlayerEvent.EventType.ReadyToPlay:
                    Debug.Log("可以播放");
                    isReady = true;
                    break;
                case MediaPlayerEvent.EventType.FirstFrameReady:
                    Debug.Log("第一帧准备好");
                    isReady = true;
                    break;
            }
        }

Guess you like

Origin blog.csdn.net/weixin_44568736/article/details/132378422