Skip to content

Instantly share code, notes, and snippets.

@shoya140
Created July 18, 2014 06:44
Show Gist options
  • Save shoya140/5aaef461626ba19aeb30 to your computer and use it in GitHub Desktop.
Save shoya140/5aaef461626ba19aeb30 to your computer and use it in GitHub Desktop.
videoView
//
// ViewController.m
// ViewoSample
//
// Created by ishimaru on 2014/07/18.
// Copyright (c) 2014年 mrk1869. All rights reserved.
//
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController (){
AVPlayer *player;
AVPlayerLayer *layer;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mov"];
player = [[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:videoPath]];
layer = [AVPlayerLayer playerLayerWithPlayer:player];
layer.frame = CGRectMake(0, 0, self.videoView.bounds.size.width, self.videoView.bounds.size.height);
[self.videoView.layer addSublayer:layer];
[layer addObserver:self forKeyPath:@"readyForDisplay" options:NSKeyValueObservingOptionNew context:NULL];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if ([keyPath isEqualToString:@"readyForDisplay"]) {
[layer removeObserver:self forKeyPath:@"readyForDisplay"];
[player play];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment