How do I construct a local movie URL properly?
In my iPhone app, the user can click a 开发者_StackOverflow社区table cell, and a movie will start playing. The movie is a local file in my project under "/Resources/myMovie.m4v". I can't figure out how to properly link to it though.
I found this code, but it doesn't seem to work:
NSString *rootPath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [rootPath stringByAppendingPathComponent:@"myMovie.m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath:filePath isDirectory:NO]];
Thanks for the help!
is the file definitely in the main bundle?
try using this to get the URL.
NSURL *url = [[NSBundle mainBundle] URLForResource:@"myMovie" withExtension:@"m4v"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
精彩评论