objective-c 多媒體 視頻播放 ( 9.0之後)

//atom

//  ViewController.murl

//  9.0之後視頻播放spa

//.net

//  Created by DC017 on 15/12/29.3d

//  Copyright © 2015 DC017. All rights reserved.orm

//視頻


#import "ViewController.h"資源

#import <AVKit/AVKit.h>get

#import <AVFoundation/AVFoundation.h>it

@interface ViewController ()

- (IBAction)bofang:(id)sender;

//試圖控制器

@property(nonatomic,strong)AVPlayerViewController * playerVC;

@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    //

    NSString * strurl=[[NSBundle mainBundle] pathForResource:@"1" ofType:@"mov"];

    //建立URL

    NSURL *url=[NSURL fileURLWithPath:strurl];

    //實例化播放試圖控制器

    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];

}


- (IBAction)bofang:(id)sender {

    //取出本地資源的相對路徑

    NSString * strurl=[[NSBundle mainBundle] pathForResource:@"1" ofType:@"mov"];

    //建立URL

    NSURL *url=[NSURL fileURLWithPath:strurl];

    //實例化播放試圖控制器

    AVPlayer * player=[AVPlayer playerWithURL:url];

    _playerVC=[[AVPlayerViewController alloc]init];

    _playerVC.player=player;

    //模態跳轉

    [self presentViewController:_playerVC animated:YES completion:nil];

}

@end

相關文章
相關標籤/搜索