AVMoviePlayer 是使用系統(tǒng)框架 MPMoviePlayerController 封裝的視頻播放器
一、功能:
1.根據(jù)手機(jī)旋轉(zhuǎn)自由切換橫豎屏;
2.手勢(shì)輕點(diǎn)顯示/隱藏topView/bottomView;
3.視頻開(kāi)始播放幾秒后topView/bottomView自動(dòng)隱藏;
4.手勢(shì)左右滑動(dòng)加載視頻快進(jìn)/快退;
5.格式支持:MOV、MP4、M4V、3GP、M3U8等。
二、使用:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//把使用視頻播放View的控制器 設(shè)置背景色為黑色
self.view.backgroundColor = [UIColor blackColor];
self.navigationController.navigationBarHidden = YES;
[self playVideo];
}
#pragma mark - 播放視頻
- (void)playVideo {
NSURL *url = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"];
[self addVideoPlayerWithURL:url];
}
- (void)addVideoPlayerWithURL:(NSURL *)url {
if (!self.videoController) {
self.videoController = [[AVMoviePlayerController alloc] initWithFrame:CGRectMake(0, 0, KSCREEN_WIDTH, KSCREEN_HEIGHT) movieTitle:@"播放時(shí)間.M3U8格式"];
__weak typeof(self)weakSelf = self;
[self.videoController setWillBackOrientationPortrait:^{
[weakSelf toolbarHidden:NO];
}];
[self.videoController setWillChangeToFullscreenMode:^{
[weakSelf toolbarHidden:YES];
}];
[self.view addSubview:self.videoController.view];
}
self.videoController.contentURL = url;
}
/**
* 隱藏navigation tabbar 電池欄
*
* @param Bool YES/NO
*/
- (void)toolbarHidden:(BOOL)Bool {
self.navigationController.navigationBar.hidden = Bool;
self.tabBarController.tabBar.hidden = Bool;
[[UIApplication sharedApplication] setStatusBarHidden:Bool withAnimation:UIStatusBarAnimationFade];
}
三、plist文件添加相關(guān)key

1253129-7c6196c55cd7472f.png
四、添加系統(tǒng)依賴(lài)框架:
AVFoundation.framework
MediaPlayer.framework
【鏈接】https://github.com/MrJalen/AVMoviePlayer
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。