//atom
// ViewController.murl
// IOS9.0後_視頻spa
//.net
// Created by dc008 on 15/12/29.3d
// Copyright © 2015年 lin. All rights reserved.orm
//視頻
#import "ViewController.h"get
#import <AVKit/AVKit.h>it
#import <AVFoundation/AVFoundation.h>io
@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