如何找到mp4资源文件的URL?

时间:2013-09-27 19:58:23

标签: objective-c video ios6 mp4

为什么我不能在“.mp4”时找到资源?

我的代码是:

- (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存在于项目导航器中,finder告诉我它位于app根文件夹中,还有main.m等。

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

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

杰夫

1 个答案:

答案 0 :(得分:1)

试试这个:

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

另一件事是确保您的文件不仅列在Project Explorer中,还包含在Copy Bundle Resources列表中。

相关问题