UnityPlugin-AVProVideo
UnityPlugin-AVProVideo copied to clipboard
Remove need to check MediaPlayer.Control / MediaPlayer.Info for Null
Describe the issue As I've been implementing AVPro Video, it's become clear that I can't count on the Control and Info properties to be available, unless the MediaPlayer has content successfully loaded into it.
The only solution seems to be trying to remember to write statements such as:
if (MediaPlayer.Control != null) { MediaPlayer.Control.Seek(time); }
This leads to my MediaPlayer code being a lot more verbose than necessary, a lot more typing, and a lot more anxiety. It introduces the risk that larger, important blocks of my code may end up occasionally halting halfway through due to a Null Reference error if the user hasn't loaded a video, and I forgot to write a null check for .Control / .Info.
There has to be some way that calls to Control or Info can fail more gracefully without throwing a Null Reference error, if a video hasn't been loaded yet - this is not an issue at all with Unity VideoPlayer.
Thank you for all the hard work you guys do on this framework!
Your Setup (please complete the following information):
- Unity version: 2020.3.16f1
- AVPro Video version: 2.1.8
- Operating system version: MacOS 11.3.1
- Device model: MacBook Pro 2017 3.1 GHz
- Video specs (resolution, frame-rate, codec, file size): N/A
To Reproduce
- Don't load a video into MediaPlayer
- Call on MediaPlayer.Control or MediaPlayer.Info
- Receive Null Reference error
Please DO NOT LINK / ATTACH YOUR PROJECT FILES HERE
Instead email the link to us [email protected]
Remember you can use the null operator:
instead of
if (MediaPlayer.Control != null) { MediaPlayer.Control.Seek(time); }
MediaPlayer.Control?.Seek(time);
But yes, you're right - we do plan to clean this up so null never has to be checked for...
Thanks,