3

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

他们从一个 URL 流式传输,它只会在 3GS 上播放,没有更低的。我试图从 for 中的通知中收集错误MPMoviePlayerControllerMPMoviePlayerContentPreloadDidFinishNotificationMPMoviePlayerPlaybackDidFinishNotification我得到了userInfo通知中键的无用错误字符串,除了无法播放电影的事实之外,这并没有告诉我任何信息。

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

在 3G 或 2G iPhone 上,MPMoviePlayerController 出现,它短暂地尝试加载电影,但随后淡出到它来自的视图控制器。

有谁知道为什么我只能在 3GS 上流式传输和播放上述 URL?我确定这是内存问题,但我在 2G iPhone 上尝试了 50MB 可用内存,但它仍然无法正常工作。

我正在使用 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];
}

谢谢

4

1 回答 1

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和你的方法中声明@interfacedealloc 。dealloc:

于 2010-09-22T00:33:20.063 回答