//
// ViewController.m
// IOS9.0后_视频
//
// Created by dc008 on 15/12/29.
// Copyright © 2015年 lin. All rights reserved.
//
#import "ViewController.h"
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property(nonatomic,strong)AVPlayerViewController *playerVC;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"心在跳" ofType:@"mp4"]];
AVPlayer *player = [AVPlayer playerWithURL:url];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = CGRectMake(0, 0, 200, 100);
[self.view.layer addSublayer:playerLayer];
[player play];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playMovie:(UIButton *)sender {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"心在跳" ofType:@"mp4"]];
//创建一个播放器
AVPlayer *player = [AVPlayer playerWithURL:url];
//实例化播放视图控制器
_playerVC = [[AVPlayerViewController alloc]init];
_playerVC.player = player;
//模态跳转
[self presentViewController:_playerVC animated:YES completion:nil];
}
@end