播放视频以启动应用程序xcode

时间:2012-09-28 20:04:05

标签: xcode ios5 media-player mpmovieplayercontroller

播放视频以启动应用程序

我有这个代码,我看不到视频,我可以听到音频。

有人可以解释原因吗?

-(void)awakeFromNib
{

    NSURL *url2 = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"tecnolitevideo_1" ofType:@"mov"]];

    moviePlayer =  [[MPMoviePlayerViewController alloc]
                    initWithContentURL:url2];
    [moviePlayer presentMoviePlayerViewControllerAnimated:moviePlayer];
    [moviePlayer.moviePlayer play];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];

}


-(void)moviePlayerPlaybackStateChanged:(NSNotification *)notification {
    }

1 个答案:

答案 0 :(得分:0)

    - (void)viewDidLoad
    {

    NSURL* url = [[NSBundle mainBundle] URLForResource:@"3" withExtension:@"mov"];

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


}

- (void) moviePlayBackDidFinish:(NSNotification*)_notification
{




    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:nil];



      [m_player.view removeFromSuperview];
      [m_player stop];

    m_player = nil;
}

我试试这个并且工作正常!!!