I am trying to create an AVPlayer that will display a video file.
This is the code I have so far:
- (IBAction) player {
NSURL* m = [[NSBundle mainBundle] URLForResource:@"Cache" withExtension:@"mov"];
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:m options:nil];
AVPlayerItem* item = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer* p = [AVPlayer playerWithPlayerItem:item];
self.player = p;
AVPlayerLayer* lay = [AVPlayerLayer playerLayerWithPlayer:p];
lay.frame = CGRectMake(10, 76, 303, 265);
[self.view.layer addSublayer:lay];
[p play];
}
I have already linked to AVFoundation.framework and CoreMedia.framework and I have imported <AVFoundation/AVFoundation.h>.
First of all, I am getting an error that says property 'player' not found on object of type 'ViewController* (for the line self.player = p;). What do I need to do to get this to run?
Also after the error is fixed, will this code work correctly to display the video?
Thanks in advance
Your viewController obviously does not contain such instance variable.
To fix that issue, add the following to your viewController header file (.h):
Then add the following to your viewController implementation file (.m):
The first step will ensure that your viewController object actually owns an instance variable named player. The second step will create a matching setter and getter.