问题
In my iPhone app, the user can click a 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!
回答1:
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];
来源:https://stackoverflow.com/questions/5372580/how-do-i-construct-a-local-movie-url-properly