MPMoviePlayerController - cannot play movies in my application on <3GS (3GS is ok)

In my application, I have several films. I checked the information for the movies, and they seem to be within what MPMoviePlayerControllershould be able to handle (bit rate, etc.).

They are broadcast from a URL, and will only play on 3GS , nothing lower. I tried to collect the error from the notifications in MPMoviePlayerControllerfor MPMoviePlayerContentPreloadDidFinishNotificationand MPMoviePlayerPlaybackDidFinishNotification, but I get a useless error line for the key userInfoin the notification that tells me nothing but the fact that the movie cannot be played.

URL I'm testing with: http://movies.apple.com/movies/independent/lawabidingcitizen/lawabidingcitizen_h.480.mov

On the iPhone 3G or 2G, MPMoviePlayerController appears and he briefly tries to download the movie, but then returns back to the view controller from where it came from.

Does anyone know why I can’t transfer and play the above URL only on 3GS? I'm sure this is a memory issue, but I tried using the iPhone 2G with 50 MB of free memory and it still does not work.

I am using a piece of code from my own sample movie streaming app from Apple to run a 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];
}

thank

+3
source share
1 answer

I think the release part is giving you problems, I use this code and it works great:

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 ready for all iOS. If you support only <3.2 use the correct part.

moviePlayBackDidFinish:, , , :

//// //// //// ///// //// //// ///// //// //// ///// //// //// ///// //// //// /
// 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.
}

moviePlayer UIViewController @interface dealloc dealloc:.

+1

Source: https://habr.com/ru/post/1731022/


All Articles