0
- (void)viewDidLoad
{
    NSString *movieFile1=[[NSBundle mainBundle]pathForResource:@"2" ofType:@"mp4"];
    self.moviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:movieFile1]];

    [super viewDidLoad];
}

我将此视频转换为 mp4,mov,3gp,m4v ,但总是:

线程1:信号SIGABRT

请帮我!

我认为这应该是格式的问题。因为当我使用来自 support.apple.com 的视频时
,此代码有效。所以我该怎么做?

4

1 回答 1

2

这样做 [super viewDidLoad]; 到顶部:

NSString *movieFile1=[[NSBundle mainBundle]pathForResource:@"2" ofType:@"mp4"];
if([[NSFileManager defaultManager] fileExistsAtPath:movieFile1])// check whether file exists
{
  self.moviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:movieFile1]];
  if(self.moviePlayer) //reference of movie player created
  {
    [self.moviePlayer prepareToPlay];
    [self.moviePlayer.view setFrame: self.view.bounds]; 
    [self.view addSubview: player.view];
    [self.moviePlayer play];
  }
}
于 2012-08-27T04:36:52.877 回答