RenderHeads / UnityPlugin-AVProVideo

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

Remove need to check MediaPlayer.Control / MediaPlayer.Info for Null #899

Open pnostudiodeveloper opened 3 years ago

pnostudiodeveloper commented 3 years ago

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):

To Reproduce

  1. Don't load a video into MediaPlayer
  2. Call on MediaPlayer.Control or MediaPlayer.Info
  3. Receive Null Reference error

Please DO NOT LINK / ATTACH YOUR PROJECT FILES HERE

Instead email the link to us unitysupport@renderheads.com

AndrewRH commented 2 years ago

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,