iOS 9.0版本最簡單的視頻播放框架AVPlayerViewContoller與畫中畫技術

一、引言

前面有一篇博客探討了iOS中視頻播放的開發相關類和方法,那篇博客中主要講解的是MeidaPlayer框架中的MPMoviePlayerController類和MPMoviePlayerViewController類。在iOS8中,iOS開發框架中引入了一個新的視頻框架AVKit,其中提供了視頻開發類AVPlayerViewController用于在應用中嵌入播放視頻的控件。在iOS8中,這兩個框架中的視頻播放功能并無太大差異,基本都可以滿足開發者的需求。iOS9系統后,iPad Air正式開始支持多任務與畫中畫的分屏功能,所謂畫中畫,即是用戶可以將當前播放的視頻縮小放在屏幕上同時進行其他應用程序的使用。這個革命性的功能將極大的方便用戶的使用。于此同時,在iOS9中,MPMoviePlayerController與MPMoviePlayerViewController類也被完全易用,開發者使用AVPlayerViewController可以十分方便的實現視頻播放的功能并在一些型號的iPad上集成畫中畫的功能。

二、AVPlayerViewController的使用與其中方法屬性解析

使用AVPlayerViewController首先需要引入兩個框架,如下:

#import <AVFoundation/AVFoundation.h>

#import <AVKit/AVKit.h>

使用如下代碼進行視頻的播放:

//此處地址也可以換成網絡地址

NSString * path = [[NSBundle mainBundle]pathForResource:@"iphone" ofType:@"mp4"];

NSURL *url = [NSURL fileURLWithPath:path];

AVPlayerViewController * play = [[AVPlayerViewController alloc]init];

play.player = [[AVPlayer alloc]initWithURL:url];

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

閱讀全文請戳這里(原文地址)

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容