IJKPlayer使用

直播拉流:
按照https://github.com/Bilibili/ijkplayer上的readme將IJKPlayer打包好,(已打包好的https://pan.baidu.com/s/1c1kB3S 提取碼: 32hn)
將打包好的IJKPlayer包拖入工程(是oc的, 引入頭文件; 是swift的, 建立橋文件), 導(dǎo)入相應(yīng)的庫:

屏幕快照 2017-01-06 下午3.34.09.png

在控制器中寫入如下代碼(基本設(shè)置代碼, 如需擴(kuò)展請(qǐng)自己添加)

import UIKit  
class ViewController: UIViewController {  
    // 在模擬器上聲音和畫面不同步或者比較卡頓的現(xiàn)象在真機(jī)沒事的,不用太擔(dān)心。  
    fileprivate var player: IJKFFMoviePlayerController?  
    override func viewDidLoad() {  
        super.viewDidLoad()  
        let options:IJKFFOptions = IJKFFOptions.byDefault();  
        // 幀速率(fps)(可以改,確認(rèn)非標(biāo)準(zhǔn)楨率會(huì)導(dǎo)致音畫不同步,所以只能設(shè)定為15或者29.97)  
        options.setOptionIntValue(15, forKey: "max-fps", of: kIJKFFOptionCategoryPlayer);  
        #if DEBUG  
           //  設(shè)置報(bào)告日志  
            IJKFFMoviePlayerController.setLogReport(true);  
            //  設(shè)置日志的級(jí)別為Debug  
            IJKFFMoviePlayerController.setLogLevel(k_IJK_LOG_DEBUG);  
        #else  
            //  設(shè)置不報(bào)告日志  
            IJKFFMoviePlayerController.setLogReport(false);  
            //  設(shè)置日志級(jí)別為信息  
            IJKFFMoviePlayerController.setLogLevel(k_IJK_LOG_INFO);  
        #endif  
        self.player = IJKFFMoviePlayerController(contentURL: URL(string: "視頻拉流地址"), with: options);  
        // 設(shè)置適配橫豎屏(設(shè)置四邊固定,長寬靈活)  
        self.player?.view.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight];  
        self.player?.view.frame = self.view.bounds;  
        // 填充fill  
        self.player?.scalingMode = IJKMPMovieScalingMode.aspectFill;  
        // 設(shè)置自動(dòng)播放(必須設(shè)置為NO,防止自動(dòng)播放,才能更好的控制直播的狀態(tài))  
        self.player?.shouldAutoplay = true;  
        self.view.autoresizesSubviews = true;  
        self.view.addSubview(self.player!.view);  
        // 播放  
        self.player?.prepareToPlay();  
    }  
    override func didReceiveMemoryWarning() {  
        super.didReceiveMemoryWarning()  
    }  
}  

另附demo(為swift版本, 跟oc差不多): https://github.com/songhaisheng/SGLive
參考的博客地址: http://www.itdecent.cn/p/a7d9ed02cf40
http://www.itdecent.cn/p/4f21af680c19
http://www.itdecent.cn/p/b8db6c142aad

最后編輯于
?著作權(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),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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