MPMoviePlayerController and the NSURL object

2019-08-26 21:36发布

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条回答
太酷不给撩
2楼-- · 2019-08-26 22:17

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

查看更多
登录 后发表回答