MPMoviePlayerController and the NSURL object

删除回忆录丶 提交于 2019-12-11 18:13:02

问题


The NSURL object returned by pathForResource is null for custom imported movie files.

 -(NSURL *)localMovieURL
{
    NSURL *theMovieURL = nil;
    NSBundle *bundle = [NSBundle mainBundle];
    if (bundle) 
    {
          NSString *moviePath = [bundle pathForResource:@"Movie"      ofType:@"m4v"];
        //NSString *moviePath = [bundle pathForResource:@"Movie_01"   ofType:@"m4v"]; 
        //NSString *moviePath = [bundle pathForResource:@"Sample"     ofType:@"m4v"];
    if (moviePath)
    {   
        theMovieURL = [NSURL fileURLWithPath:moviePath];
        }

    NSLog(@" MMM moviePath   = %@", moviePath);
    NSLog(@" UUU theMovieURL = %@", theMovieURL);

}

return theMovieURL;

}

Consider the above sample code from Apple (Sample Project name - MoviePlayer)

https://developer.apple.com/library/ios/navigation/index.html?section=Resource+Types&topic=Sample+Code

Movie.m4v comes with the sample and the compiled sample project plays the m4v with no problem at all. But when I make a copy of Movie.m4v, name it Movie_01.m4v and drag the file into the project, the MPMoviePlayerController has no response. Also the added NSLog output (begins with MMM and UUU becomes "...= (null)". The same goes for the sample m4v "Sample.m4v" which I make myself with iMovie.

This question is related to the question I posted earlier (here). My previous question involves a project which I wrote myself and it has the same problem : The "pathForResource" method returns "nil" even the movie files are seemingly properly imported. The sample movies can all play perfectly inside Xcode and I have imported (drag) png photo files into the project in the same way. But the png photos can be displayed by the compiled program both on the phone and the simulator as expected.

Hope somebody can give some hints.


回答1:


It seems you duplicated your question. Both answers seems to be: add the movie to your application bundle (Project Build Steps > Copy Resources)



来源:https://stackoverflow.com/questions/9728863/mpmovieplayercontroller-and-the-nsurl-object

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