【问题标题】:My video couldn't play with MPMoviePlayer?xcode我的视频无法使用 MPMoviePlayer 播放?xcode
【发布时间】:2012-08-29 13:28:45
【问题描述】:
- (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 的视频时
,此代码有效。那我该怎么办?

【问题讨论】:

  • 尝试将[super viewDidLoad];移到顶部?

标签: xcode video


【解决方案1】:

作为 [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];
  }
}

【讨论】:

  • MPMoviePlayerController 确实显示在您的屏幕上。还有调试代码
  • 我发现了问题,我没有将视频复制到文件夹中!谢谢
  • 所以文件不会在应用程序中退出
猜你喜欢
  • 2018-11-15
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-05
  • 2012-12-06
  • 1970-01-01
相关资源
最近更新 更多