views:

296

answers:

1

In my app, I have some movies playing. I have checked the information for the movies and they appear to be within what MPMoviePlayerController should be able to handle (bitrate, etc.)

They're streaming from a URL, and it will only play on a 3GS, nothing lower. I have tried to collect the error from the notifications in MPMoviePlayerController for MPMoviePlayerContentPreloadDidFinishNotification and MPMoviePlayerPlaybackDidFinishNotification but I am getting a useless error string for the userInfo key in the notification, that doesn't tell me anything but the fact that the movie could not be played.

The URL I am testing with is: http://movies.apple.com/movies/independent/lawabidingcitizen/lawabidingcitizen_h.480.mov

On a 3G or 2G iPhone the MPMoviePlayerController appears and it briefly tries to load the movie but then fades back to the view controller where it came from.

Does anyone have a clue why I am unable to stream and play the above URL only on a 3GS? I am sure it's a memory issue, but I have tried on a 2G iPhone with 50MB memory free and it still doesn't work.

I am using the piece of code from Apple's own sample app for streaming movies to launch the movie:

MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://movies.apple.com/movies/independent/lawabidingcitizen/lawabidingcitizen_h.480.mov"];
if (mp) {
    self.moviePlayer = mp;
    [mp release];
    [self.moviePlayer play];
}

Thanks

A: 

I think the release part is giving you trouble, i'm using this code and works fine:

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

    //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// /
    // ONLY FOR IOS 3.2 or later
    if ( kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_2 ) {

        // May help to reduce latency
        [moviePlayer prepareToPlay];

        /// //// //// //// //// //// //// //// //// //// //// //// //// //// /
        // Set the correct frame for Movie Controller.
        moviePlayer.view.frame = self.view.frame;

        /// //// //// //// //// //// //// //// //// //// //// //// //// //// /
        // Autorezing the view, allows him to adjust with the orientation.
        moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        moviePlayer.view.autoresizesSubviews = YES;

        /// //// //// //// //// //// //// //// //// //// //// //// //// //// /
        // Add to screen.
        [self.view addSubview:moviePlayer.view];
    } 

    //// //// //// ///// //// //// ///// //// //// ///// //// //// ///// //// //// /
    // Older than 3.2
    else {
        // Play Movie.
        [moviePlayer play];

        // Register to receive a notification when the movie has finished playing. 
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePlayBackDidFinish:) 
                                                     name:MPMoviePlayerPlaybackDidFinishNotification 
                                                   object:nil];
    }

This code is prepared for all iOSs. If you only support < 3.2 use the correct part.

You should implement an method moviePlayBackDidFinish: to receive an notification when the movie finish to play, as follow:

//// //// //// ///// //// //// ///// //// //// ///// //// //// ///// //// //// /
// Notification called when the movie finished playing. This Call is only for iOS 3.2
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
    // Unregister. 
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:nil];

    // Your finish code here.
}

You must declare the moviePlayer in your UIViewController @interface and dealloc in your dealloc: method.

SEQOY Development Team