0

`我在开发用于在 ios5 Xcode 编程中运行 mp4 视频的代码时遇到问题。当我运行应用程序时,虽然clip2.mp4 文件在我的bundle 中,但会显示。请给我一个适当的解决方案

  - (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];    
   } `
4

1 回答 1

0

它应该是

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

url已经是一个NSURL. -fileURLWithPath:用于从包含文件路径 (ie ) 而不是普通 URL (ie )的NSURLfrom创建一个NSString/path/to/filehttp://stackoverflow.com/

于 2012-05-11T13:05:28.527 回答