RenderHeads / UnityPlugin-AVProVideo

AVPro Video is a multi-platform Unity plugin for advanced video playback
https://www.renderheads.com/products/avpro-video/
231 stars 28 forks source link

Error event not firing #443

Closed blevok closed 4 years ago

blevok commented 4 years ago

I'm having an issue with the error event. I need to know when a video fails to load, so i can close my spinny loading indicator, show an error message, and do other stuff. I have all events selected in the media player component, and every other event that i use works fine, but the error event only works in some cases.

Here is my code:

public void OnVideoEvent(MediaPlayer mp, MediaPlayerEvent.EventType et, RenderHeads.Media.AVProVideo.ErrorCode errorCode)
{
    switch (et)
    {
        case MediaPlayerEvent.EventType.FirstFrameReady:
            LoadingIcon.gameObject.SetActive(false);
            break;

        case MediaPlayerEvent.EventType.Error:
            LoadingIcon.gameObject.SetActive(false);
            Invoke("VrShowError", 1);
            Invoke("VrHideError", 4);
            closeVideo();
            break;
    }
    Debug.Log("Event: " + et.ToString());
}

FirstFrameReady works, and the code in the callback executes. Same for closing, metadataready, and others. When i try to load a video that has no issue, but just isn't a supported format or something, it fails, and the error event fires. But i also need to catch issues like corrupted/broken videos. To test this, i made a text file and named it fake_video.mp4 and tried to load it. Of course it fails, and error logs are generated, but the event does not fire.

Here is what i see in the log after closing a good video, and opening the bad video: projectconsole

I'm using unity 2019.3.2f1 on windows 10, and avpro 1.11.2 I see this issue in the android build and in the editor.

AndrewRH commented 4 years ago

So that error comes directly as the file is opening and it fails right away - that is why there's no event for it. Sort of like if you try to open a file that doesn't exist.

When you call OpenVideoFromFile() you should check the return value - if it returns false then it failed to find/load the file. The event is used for problems with loading once the media has been found.

Does that help?

blevok commented 4 years ago

Oh I didn't realize OpenVideoFromFile returned a bool. That makes sense. Thank you.