播放视频Ipad Ios6

时间:2012-11-11 18:46:56

标签: ios xcode video ios6 media-player

我需要在应用程序启动时播放视频

我的代码适用于Iphone Ipad Simulator

但不是在设备上物理Ipad

怎么了?

- (void)viewDidLoad
    {

         if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

            NSURL* url = [[NSBundle mainBundle] URLForResource:@"Intro3" withExtension:@"mp4"];

            m_player = [[MPMoviePlayerController alloc] initWithContentURL:url];
            [m_player.backgroundView setBackgroundColor:[UIColor blackColor]];
            [m_player.view setBackgroundColor:[UIColor blackColor]];
            [m_player setControlStyle:MPMovieControlStyleNone];
            [[m_player view] setFrame:[self.view bounds]];

            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
            [m_player play];
            [self.view addSubview:[m_player view]];

            }
            else{
               ---play video in iphone---
            }

    }

2 个答案:

答案 0 :(得分:2)

代码完美无缺!!!

问题在于视频的分辨率太大了。

调整大小和工作=)

答案 1 :(得分:0)

我建议你改用MPMoviePlayerViewController

 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

            NSURL* url = [[NSBundle mainBundle] URLForResource:@"Intro3" withExtension:@"mp4"];

            MPMoviePlayerViewController * controller = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
            [self  presentMoviePlayerViewControllerAnimated:controller];
            [controller release];
}