Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are several issues here:</p> <ol> <li><p>For this type of usage (integrating the player into your view), you should be using <code>MPMoviePlayerController</code>, not <code>MPMoviePlayerViewController</code>. Use <code>MPMoviePlayerViewController</code> when you want to have a self-contained view controller which can be presented using <code>presentMoviePlayerViewControllerAnimated:</code>.</p></li> <li><p>Assuming you are using ARC, the main problem is that nothing is keeping a reference to your player object. As a consequence, the player is disappearing shortly after you create it. You should keep a reference to it by assigning it to a property or instance variable of your view controller.</p> <p>For a full example of this, see <a href="https://stackoverflow.com/users/91282/till">Till</a>'s excellent <a href="https://stackoverflow.com/a/15065878/6111">answer to a similar question</a>.</p></li> <li><p>I'm not sure what your intended purpose of the <code>UIGraphicsBeginImageContext</code> and <code>UIGraphicsEndImageContext</code> calls are, but I can't see that they're needed here.</p></li> </ol> <hr> <p>As for <code>shouldAutoplay = NO</code>, the video is still starting because you are calling <code>play</code> immediately afterwards.</p> <hr> <p>The player's <code>duration</code> property only contains a useful value after a <code>MPMovieDurationAvailableNotification</code> has been received. You'll need to do something similar to the following to have access to the actual duration:</p> <pre><code>__weak MediaPlayerController *weakSelf = self; [[NSNotificationCenter defaultCenter] addObserverForName:MPMovieDurationAvailableNotification object:self.player queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { NSLog(@"Movie duration: %lf", weakSelf.player.duration); }]; </code></pre> <p>Use <code>removeObserver:name:object:</code> to remove the observer when you are done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload