How can I play mp4 resource using AVPlayer?

In my project navigator, I have included the mp4 resource. I want to play it in AVPlayer. I know how to create an AVPlayerItem for an AVPlayer object, and now I would like to load the corresponding AVAsset into it, pointing to my mp4 resource. The problem is that AVAsset has only the assetWithURL method: to create AVAsset. I need the assetWithName: method, but this method does not exist. How can I play mp4 file if i don't have url? If this cannot be reproduced using the name link, how can I get the file url for my mp4 file?

+5
source share
2 answers

To get the url use

[[NSBundle mainBundle] URLForResource:@"my_video" withExtension:@"mp4"]
+12
source

, , URL

- (NSString*) saveFilePath: (NSString *) add
{
    NSString *filename = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:
                    [[NSBundle mainBundle] pathForResource:add ofType:@"mp4"]isDirectory:NO]]];
    return filename;
}

, [self saveFilePath:@"Name of your file"], URL.

:

AVPlayer *player = [[AVPlayer alloc] initWithURL:[self saveFilePath:@"fileName"];
[player play];
-1