視頻播放 iOS8.0 與iOS 9.0

來源:互聯網
上載者:User

標籤:

#import "ViewController.h"#import <AVFoundation/AVFoundation.h>#import <AVKit/AVKit.h>#import <MediaPlayer/MediaPlayer.h>@interface ViewController ()@property(nonatomic ,strong)MPMoviePlayerController * PlayerController;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];   //    [self test1];    }-(void)test {        //iOS 9.0 視頻播放    //建立視頻播放控制器    AVPlayerViewController * playVc = [[AVPlayerViewController alloc]init];        NSString * path = [[NSBundle mainBundle]pathForResource:@"Alizee_La_Isla_Bonita副本.mp4" ofType:nil];    //設定屬性    playVc.player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:path]];        //    [self presentViewController:playVc animated:YES completion:nil];    //    //設定播放器控制器的View 的大小    playVc.view.frame = CGRectMake(0, 0, 300, 300);    //播放    [playVc.player play];            //將播放器的view添加到View上    [self.view addSubview:playVc.view];    }-(void)test1 {               //iOS 8.0 有介面的    //擷取資源路徑    NSURL * url   = [[NSBundle mainBundle]URLForResource:@"Alizee_La_Isla_Bonita副本.mp4" withExtension:nil];        NSLog(@"%@",url);        //建立播放器控制器    MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];            //播放        [self presentViewController:playerController animated:YES completion:nil];                }-(void)test2 {    //    iOS 8.0 無介面        //擷取資源路徑        NSURL * url = [[NSBundle mainBundle]URLForResource:@"Alizee_La_Isla_Bonita副本.mp4" withExtension:nil];        //建立視頻播放器        MPMoviePlayerController * PlayerController = [[MPMoviePlayerController alloc]initWithContentURL:url];        //一定要強引用,否則就無法播放視頻    self.PlayerController = PlayerController;        //準備播放        [PlayerController prepareToPlay];        //設定樣式        PlayerController.controlStyle = MPMovieControlStyleFullscreen;        PlayerController.view.frame = CGRectMake(0, 0, 300, 300);    //    PlayerController.view.frame = self.view.bounds;        [self.view addSubview:PlayerController.view];        [PlayerController play];            }

  

視頻播放 iOS8.0 與iOS 9.0

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.