user1603173
user1603173

Reputation: 7

My video couldn't play with MPMoviePlayer?xcode

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

    [super viewDidLoad];
}

I turned this video to mp4,mov,3gp,m4v ,but always:

Thread 1:signal SIGABRT

Please help me!

I think it should the problem of format .Because when I use the video from support.apple.com
,this code works. So what should I do?

Upvotes: 0

Views: 334

Answers (1)

Paresh Navadiya
Paresh Navadiya

Reputation: 38249

do this as [super viewDidLoad]; to the top:

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

Upvotes: 2

Related Questions