NSBundle pathforResource,放置电影文件的位置
我不太确定 pathForResource 是如何工作的。我想通过我的应用程序播放一部电影。我将其拖到 XCode 中,选中该框以将其添加到子文件夹并根据需要创建目录。我将其放在一个名为“视频”的单独文件夹中。这个应用程序没有资源文件夹(有人删除了它,并认为最好只为每种类型的资源(img、vid 等)提供文件夹。所以我不确定将我的电影放在哪里,以及如何使用 NSBundle 方法访问它,这是我所拥有的,但它似乎无法播放,
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(120, 120, 300, 200)];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
谢谢。
I'm not quite sure how pathForResource works. I wanted to play a movie from my app. I dragged it into XCode, checking the box to add it to subfolders and create directory if needed. I placed it in a separate folder called Videos. There is no Resources folder for this app (someone deleted it and thought it would be better to just have folders for each type of resource (img, vid, etc). So I'm not sure where to drop my movie, and how to access it using the NSBundle methods. This is what I have, but it does not seem to play.
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(120, 120, 300, 200)];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码应该列出 mainBundle 中的所有内容
,或者您可以转到 ~user/Library/Application Support/iPhone Simulator 并找到您的应用程序,然后右键单击它并显示内容以查看应用程序的目录结构。
this code should list everything in your mainBundle
Or you could just go to the ~user/Library/Application Support/iPhone Simulator and find you app and right click on it and show the content to see the directory structure of your app.