【问题标题】:MPMoviePlayerController - unable to play movies in my app on < 3GS (3GS is fine)MPMoviePlayerController - 无法在我的应用中以 < 3GS 播放电影(3GS 很好)
【发布时间】:2010-02-02 14:31:59
【问题描述】:

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

它们从一个 URL 流式传输,并且它只能在 3GS 上播放,不会更低。我试图从MPMoviePlayerController 中的通知中为MPMoviePlayerContentPreloadDidFinishNotificationMPMoviePlayerPlaybackDidFinishNotification 收集错误,但我收到通知中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];
}

谢谢

【问题讨论】:

    标签: iphone mpmovieplayercontroller


    【解决方案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。如果你只支持

    您应该实现一个方法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.
    }
    

    您必须在您的 UIViewController @interface 中声明 moviePlayer 并在您的 dealloc: 方法中声明。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多