Objective c 如何找到mp4资源文件的URL?
当资源是“.mp4”时,为什么我找不到它 我的代码是:Objective c 如何找到mp4资源文件的URL?,objective-c,video,ios6,mp4,Objective C,Video,Ios6,Mp4,当资源是“.mp4”时,为什么我找不到它 我的代码是: - (IBAction)babelFishButton:(id)sender { NSURL *url = [[NSBundle mainBundle] URLForResource:@"BabelFish" withExtension:@"mp4"]; MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL:
- (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告诉我它与main.m等一起存在于应用程序根文件夹中
但视频不会播放,因为url为零(找不到文件)。我可以粘贴文件的副本并将其重命名为“BabelFish.txt”,更改代码中的扩展名,它就会找到该文件
为什么它找不到“mp4”文件?如何获取mp4文件的URL
杰夫试试这个:
NSString *myUrlSTR = [[NSBundle mainBundle] pathForResource:@"BabelFish" ofType:@"mp4"];
另一件事是确保您的文件不仅列在您的项目资源管理器中,而且还包括在您的复制包资源列表中