直播拉流:
按照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