【问题标题】:MPMoviePlayerController problems on iPadiPad 上的 MPMoviePlayerController 问题
【发布时间】:2010-03-30 14:32:01
【问题描述】:

我正在尝试在 iPad 上使用 MPMoviePlayerController 类。

这是我的代码:

multimediaPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];               
multimediaPlayer.movieControlMode = MPMovieControlModeDefault;
[multimediaPlayer play];

这在 iPhone 上运行良好,但不想在 iPad 上运行。我听到视频的声音,但电影没有播放。 为什么会是这个问题?

【问题讨论】:

  • 好的,伙计们,我发现: 已被弃用。解决方案是 mediaPlayer.controlStyle = MPMovieControlStyleDefault;但它仍然不起作用。
  • 这是一个答案,应该作为答案发布.. 你可以稍后编辑你的答案,因为你有更多信息

标签: objective-c ipad iphone-sdk-3.0


【解决方案1】:

下面的代码非常适合我的应用程序。希望它对你也一样。 主要是设置mpMoviePlayerController的frame的frame。如果你不这样做,它几乎不会显示视频。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

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

    // Register to receive a notification when the movie scaling mode has changed. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(movieScalingModeDidChange:) 
                                                 name:MPMoviePlayerScalingModeDidChangeNotification 
                                               object:nil];
    kDomain = [NSString stringWithString:@"http://www.virtua-book.com/"];
    [navigationController setNavigationBarHidden:YES];

    NSURL *ur=[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"IPAD" ofType:@"mp4"]];
    mpMCtr=[[MPMoviePlayerController alloc] initWithContentURL:ur];
    mpMCtr.fullscreen=YES;
    [mpMCtr setScalingMode:MPMovieScalingModeFill];
    [mpMCtr setShouldAutoplay:YES];
    [mpMCtr setControlStyle:MPMovieControlStyleNone];
    [mpMCtr setMovieSourceType:MPMovieSourceTypeFile];
    mpMCtr.view.frame = CGRectMake(0, 0, 1024, 768);
    [mpMCtr setRepeatMode:MPMovieRepeatModeNone];

    [mpMCtr play];

    [ur release];

    // Override point for customization after app launch    
    [navigationController.view addSubview:mpMCtr.view];
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];

    return YES;
}


//  Notification called when the movie finished playing.
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
    [mpMCtr.view removeFromSuperview];
}

【讨论】:

    【解决方案2】:

    要修复后退/前进(或上一个/下一个)按钮,您应该执行以下操作:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
    
    ...
    
    - (void) moviePlayerPlaybackStateDidChange: (NSNotification *) notification {
     if (moviePlayer.playbackState == MPMoviePlaybackStateStopped) {
      [moviePlayer setContentURL:[moviePlayer contentURL]];
      [moviePlayer play];
     }
    }
    

    【讨论】:

      【解决方案3】:

      类似的事情可能是你想要做的:

      MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentUrl:movieUrl];
      [self presentMoviePlayerViewController:mpvc];
      

      【讨论】:

        【解决方案4】:
        MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc]initWithContentURL:movieURL];
        mp.moviePlayer.controlStyle = 2;
        

        【讨论】:

          【解决方案5】:

          好的,伙计们,我发现 this: 已被弃用。

          解决方案是multimediaPlayer.controlStyle = MPMovieControlStyleDefault;,但还是不行。

          【讨论】:

          • 你的问题得到答案了吗?我也陷入了同样的困境。
          • 如果你有答案可以和我们分享吗?
          • 您必须将 MPMoviePlayerController 的视图添加到您的视图中,但是如果您仔细阅读新文档,您会发现这是一个很大的优势。希望对您有所帮助。
          • 现在它可以工作了,看看我的回答 - 我最初也有同样的问题。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-02-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-01-11
          相关资源
          最近更新 更多