幾種播放視頻文件的方式(六) —— 基于MobileVLCKit框架的視頻播放之簡單示例(二)

版本記錄

版本號 時間
V1.0 2017.12.31

前言

iOS系統(tǒng)中有很多方式可以播放視頻文件,這里我們就詳細(xì)的說明下播放視頻文件的原理和實(shí)例。希望能幫助到大家,大家能喜歡。感興趣的可以參考上面幾篇。
1. 幾種播放視頻文件的方式(一) —— 總結(jié)播放視頻的幾種方式(一)
2. 幾種播放視頻文件的方式(二) —— 基于MediaPlayer框架的視頻播放(一)
3. 幾種播放視頻文件的方式(三) —— 基于AVFoundation框架視頻播放(一)
4. 幾種播放視頻文件的方式(四) —— 基于AVKit框架的視頻播放(一)
5. 幾種播放視頻文件的方式(五) —— 基于MobileVLCKit框架的視頻播放(一)

功能需求

基于MobileVLCKit框架視頻播放的簡單實(shí)例。


功能實(shí)現(xiàn)

下面我們就看一下功能實(shí)現(xiàn)。

1. 下載庫文件

這個文件很大好幾百M(fèi),但是編譯之后只有幾M而已,如下:

2. 項(xiàng)目庫中添加文件

Linked Frameworks and Libraries中添加下載完成的MobileVLCKit

3. 添加依賴框架,如下圖所示。

4. 修改編譯選項(xiàng),由于該框架底層由C++所編寫,所以我們需要更改相關(guān)的編譯選項(xiàng)

5. 修改Framework Search Paths,否則工程無法找到該框架

6. 代碼實(shí)現(xiàn)

下面我們就看一下代碼實(shí)現(xiàn)。

1. 本地視頻播放
//控制器
- (void)localPlay
{
    //這個是播放器
    JJVLCPlayer *player = [[JJVLCPlayer alloc] init];
    
    player.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width / 16 * 9);
    player.center = self.view.center;
    player.mediaURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] URLForResource:@"movie.mp4" withExtension:nil]];

    [player showInView:self.view.window];
}

//播放器
- (void)showInView:(UIView *)view 
{  
    NSAssert(_mediaURL != nil, @"JJVLCPlayer Exception: mediaURL could not be nil!");
    
    [view addSubview:self];
    
    self.alpha = 0.0;
    [UIView animateWithDuration:kVideoPlayerAnimationTimeinterval animations:^{
        self.alpha = 1.0;
    } completion:^(BOOL finished) {
        [self play];
    }];
}

2. 網(wǎng)絡(luò)視頻播放
//控制器
- (void)localPlay
{
    JJVLCPlayer *player = [[JJVLCPlayer alloc] init];
    
    player.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width / 16 * 9);
    player.center = self.view.center;
    player.mediaURL = [NSURL URLWithString:@"http://202.198.176.113/video002/2015/mlrs.rmvb"];
    
    [player showInView:self.view.window];
}

//播放器
- (void)showInView:(UIView *)view 
{  
    NSAssert(_mediaURL != nil, @"JJVLCPlayer Exception: mediaURL could not be nil!");
    
    [view addSubview:self];
    
    self.alpha = 0.0;
    [UIView animateWithDuration:kVideoPlayerAnimationTimeinterval animations:^{
        self.alpha = 1.0;
    } completion:^(BOOL finished) {
        [self play];
    }];
}

上面只是簡單的播放器播放實(shí)現(xiàn),具體的皮膚還需要大家自己根據(jù)項(xiàng)目需求添加。

后記

未完,待續(xù)~~~~

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容