Home > Back-end >  Why Try Catch dont working on VideoPlayer Prepare() method?
Why Try Catch dont working on VideoPlayer Prepare() method?

Time:08-27

I want to catch an exception when the url for VideoPlayer is broken, but try{}catch{} didn't catch this exeption.

VideoPlayer cannot play url : http://svtaneko-migration.com:8080/video/test.mp4

Cannot read file.

My method

public async void Initialize(string url){
    errorText.text = string.Empty;
                              
    _videoPlayer.url = "http://svtaneko-migration.com:8080/video/test.mp4";
    _videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
    _videoPlayer.targetTexture = rendererTexture;
             
    _videoPlayer.errorReceived  = OnPlayerErrorReceived;
        
    try{
        _videoPlayer.Prepare();
        while (!_videoPlayer.isPrepared)
            await UniTask.Yield();
     }
      catch{}
    }

Has anyone solved this problem

CodePudding user response:

What you see in the console is not the result of an actual Exception that is thrown and could be handled by the try - catch.

Unity rather already internally handled this and only prints a Debug.LogError / Debug.LogException for this

=> There is nothing actually thrown you can catch here.

  • Related