We're hiring!

We're actively seeking developers & designers for our new Detroit location. Learn more

MPMoviePlayerViewController: Check yourself before you wreck yourself

iOS pop quiz:

~90% of the time, this code will show a video.

~10% of the time, this code will show a screen with multimedia controls but no video.

If the user rotates their device, the video will then show correctly, even if the user rotates it back.

Why? And how do we fix it?

No idea yet. Let’s check the loadState, just for fun.

When it works, the loadState is 3.

When it fails, the loadState is 0.

Interesting.

For reference, this is what 3 and 0 map to:

MPMovieLoadStateUnknown

Cryptic. Let’s check the docs and see what it means.



Image and video hosting by TinyPic



MPMovieLoadStateUnknown

The load state is not known at this time.

Available in iOS 3.2 and later.

Declared in MPMoviePlayerController.h.

Okay. Since the documentation is “concise” at best, let’s just assume that the video isn’t ready yet, for whatever reason. And, once we’ve forced it out into the limelight, it just stands there trembling with stage fright no matter how long we wait—unless we rotate the device, which is the iOS equivalent of yelling “Snap out of it!” and delivering a firm slap to the face.

So what’s the solution? Simply check yourself, lest you wreck yourself.

It ain’t pretty, but it fixes this subtle bug that probably exists in most apps that play movies.

This entry was posted in Design & Development, Languages, Mobile. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Justin DeWind
    Posted September 2, 2010 at 9:39 pm

    fourthversion,

    That is a far more elegant solution. I don’t know why I didn’t think of that. Great tip!

  2. Posted September 2, 2010 at 9:39 pm

    Have you considered using KVO to determine when the laodState becomes ‘valid’? Just a thought. Good stuff.

  3. Raj
    Posted March 5, 2012 at 9:50 am

    This doesn’t work on iOS 5.0.1!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">