AVMoviePlayer_視頻播放器

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)載。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容