視頻播放
1> AVPlayer
能播放本地、遠程的音頻晶伦、視頻文件
基于Layer顯示碟狞,得自己去編寫控制面板2> MPMoviePlayerController
能播放本地、遠程的音頻婚陪、視頻文件
自帶播放控制面板(暫停族沃、播放、播放進度、是否要全屏)3> MPMoviePlayerViewController
能播放本地脆淹、遠程的音頻常空、視頻文件
內(nèi)部是封裝了MPMoviePlayerController
播放界面默認就是全屏的
如果播放功能比較簡單,僅僅是簡單地播放遠程盖溺、本地的視頻文件漓糙,建議用這個
區(qū)別
1.AVPlayer(遠程?音樂/播放視頻)—>添加layer
2.MPMoviePlayerController—>給.view設(shè)置frame,將這個view 添加到某?一個View
3.MPMoviePlayerViewController(modal出來,?自動播放,?一定全 屏播放)
1:AVPlayer
- 可以播放遠程視頻(需要通過添加layer來顯示視頻)
#pragma mark - 懶加載代碼
- (AVPlayer *)player
{
if (_player == nil) {
// 1.獲取URL(遠程/本地)
// NSURL *url = [[NSBundle mainBundle] URLForResource:@"01-知識回顧.mp4" withExtension:nil];
NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/a45016f4-08d6-4277-abe6-bcfd5244c201/L.mp4"];
// 2.創(chuàng)建AVPlayerItem
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:url];
// 3.創(chuàng)建AVPlayer
_player = [AVPlayer playerWithPlayerItem:item];
// 4.添加AVPlayerLayer
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player];
layer.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width * 9 / 16);
[self.view.layer addSublayer:layer];
}
return _player;
}
2:MPMoviePlayerController
#import <MediaPlayer/MediaPlayer.h>
#pragma mark - 懶加載代碼
- (MPMoviePlayerController *)playerController
{
if (_playerController == nil) {
// 1.獲取視頻的URL
NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/19954d8f-e2c2-4c0a-b8c1-a4c826b5ca8b/L.mp4"];
// 2.創(chuàng)建控制器
_playerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
// 3.設(shè)置控制器的View的位置
_playerController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width * 9 / 16);
// 4.將View添加到控制器上
[self.view addSubview:_playerController.view];
// 5.設(shè)置屬性
_playerController.controlStyle = MPMovieControlStyleNone;
}
return _playerController;
}
3:MPMoviePlayerViewController
#import <MediaPlayer/MediaPlayer.h>
#pragma mark - 懶加載
- (MPMoviePlayerViewController *)playerVc
{
if (_playerVc == nil) {
NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/a45016f4-08d6-4277-abe6-bcfd5244c201/L.mp4"];
_playerVc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];;
}
return _playerVc;
}
- (IBAction)play {
[self presentMoviePlayerViewControllerAnimated:self.playerVc];
}