视频播放器无法在Xcode 4.2中工作

时间:2012-05-11 13:02:49

标签: objective-c

`我在ios5 Xcode编程中开发运行mp4视频的代码时遇到问题。    当我运行app注意显示虽然clip2.mp4文件在我的bundle.please给我一个         适当的解决方案

  - (void)viewDidLoad
  {
   [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

  NSString *url = [[NSBundle mainBundle]
                 pathForResource:@"clip2"
                 ofType:@"mp4"];
 player =[[MPMoviePlayerController alloc]
   initWithContentURL:[NSURL fileURLWithPath:url]];
  [player prepareToPlay];
   [player play];    


   [[NSNotificationCenter defaultCenter]
 addObserver:self
   selector:@selector(movieFinishedCallback:)                                                 
   name:MPMoviePlayerPlaybackDidFinishNotification
   object:player];

  //---play movie---

 }

   - (void) movieFinishedCallback:(NSNotification*) aNotification {
  MPMoviePlayerController *play= [aNotification object];
   [[NSNotificationCenter defaultCenter]
   removeObserver:self
    name:MPMoviePlayerPlaybackDidFinishNotification
    object:play];    
   /    / [player autorelease];    
   } `

1 个答案:

答案 0 :(得分:0)

应该是

player = [[MPMoviePlayerController alloc] initWithContentURL:url];

url已经是NSURL-fileURLWithPath:用于从包含文件路径(即NSURL)的NSString创建/path/to/file,而不是普通网址(即http://stackoverflow.com/