开发者

NSBundle pathforResource, where to place movie file

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 movi开发者_如何学编程e, 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜