NSBundle pathforResource,放置电影文件的位置

发布于 2024-12-08 01:53:24 字数 1076 浏览 0 评论 0原文

我不太确定 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞取 2024-12-15 01:53:24

这段代码应该列出 mainBundle 中的所有内容

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];
NSArray *files = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.m4v'"]];
NSLog(@"Directory Start");
NSLog(@"%@",dirContents);
NSLog(@"Directory End");
NSLog(@"files: %@",files);

,或者您​​可以转到 ~user/Library/Application Support/iPhone Simulator 并找到您的应用程序,然后右键单击它并显示内容以查看应用程序的目录结构。

this code should list everything in your mainBundle

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];
NSArray *files = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.m4v'"]];
NSLog(@"Directory Start");
NSLog(@"%@",dirContents);
NSLog(@"Directory End");
NSLog(@"files: %@",files);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文