MPMoviePlayerController - 无法在我的应用程序中播放电影< 3GS(3GS很好)

时间:2010-02-02 14:31:59

标签: iphone mpmovieplayercontroller

在我的应用中,我有一些电影在播放。我检查了电影的信息,它们似乎在MPMoviePlayerController应该能够处理的范围内(比特率等)

他们从网址流式传输,而只能在3GS上播放,而不是更低。我试图从MPMoviePlayerController MPMoviePlayerContentPreloadDidFinishNotificationMPMoviePlayerPlaybackDidFinishNotification的通知中收集错误,但我收到通知中userInfo项的无用错误字符串,除了电影无法播放之外,别告诉我任何事情。

我正在测试的网址是:http://movies.apple.com/movies/independent/lawabidingcitizen/lawabidingcitizen_h.480.mov

在3G或2G iPhone上出现MPMoviePlayerController,它会短暂地尝试加载电影,但然后逐渐消失回到它来自的视图控制器。

有没有人知道为什么我无法仅在3GS上播放和播放上述网址?我确信这是一个内存问题,但我已经尝试了一款免费内存为50MB的2G iPhone,但它仍无效。

我正在使用Apple自己的示例应用程序中的一段代码来播放电影:

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];
}

由于

1 个答案:

答案 0 :(得分:1)

我认为发布部分给你带来麻烦,我正在使用这段代码并且工作正常:

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];
    }

此代码适用于所有iOS。如果你只支持< 3.2使用正确的部分。

您应该实施一种方法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。