How do I construct a local movie URL properly?

孤者浪人 提交于 2019-12-08 07:56:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!