2013-09-27 15 views
0

为什么当它是“.mp4”时我找不到资源?如何查找mp4资源文件的URL?

我的代码是:

- (IBAction)babelFishButton:(id)sender { 
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"BabelFish" withExtension:@"mp4"]; 
    MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: url]; 
    [player prepareToPlay]; 
    [player.view setFrame: self.imageView.bounds]; // player's frame must match parent's 
    [self.imageView addSubview: player.view]; 
    [player play]; 
} 

BabelFish.mp4在Project Navigator中存在,并且取景器告诉我这是在应用程序的根文件夹,用的main.m一起等

但视频不播放,因为url是零(该文件未找到)。我可以粘贴该文件的副本并将其重命名为“BabelFish.txt”,更改代码中的扩展名并找到该文件。

为什么找不到“mp4”文件?我如何获得mp4文件的URL?

杰夫

回答

1

试试这个:

NSString *myUrlSTR = [[NSBundle mainBundle] pathForResource:@"BabelFish" ofType:@"mp4"]; 

另一件事请确保您的文件,不仅在你的项目资源管理器中,但也包含在您复制包资源列表。