該文章一直被鎖定琅关,于是決定重新整理思路重新寫一遍煮岁。也去繁就簡
記錄ijkplayer從一無所知到播放這個流程
-
先cd到你喜愛的目錄下
-
Build iOS
執(zhí)行git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios
克隆ijkplayer-ios
-
cd到ijkplayer-ios文件夾下創(chuàng)建新分支并切換過去
git checkout -B latest k0.8.8
-
分支創(chuàng)建完后運(yùn)行腳本
./init-ios.sh
pull gas-preprocessor base
pull ffmpeg base
pull ffmpeg fork armv7
pull ffmpeg fork arm64
pull ffmpeg fork i386
pull ffmpeg fork x86_64
-
cd到ios文件夾,運(yùn)行腳本
./compile-ffmpeg.sh clean
和./compile-ffmpeg.sh all
- 編譯IJKMediaDemo.xcodeproj可能會報錯
'libavformat/avformat.h' file not found
發(fā)現(xiàn)問題就在issues里找答案涣易,參考#1251
1.進(jìn)入ijkplayer-ios/ios/compile-ffmpeg.sh
2.找到這一行 FF_ALL_ARCHS_IOS8_SDK="armv7 arm64 i386 x86_64"
3.刪除掉其中的 armv7
4.回到ijkplayer-ios/ios画机,并執(zhí)行
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all
其實(shí),在執(zhí)行./compile-ffmpeg.sh all
的時候已經(jīng)報錯了新症,只是選擇了忽略
現(xiàn)在步氏,刪掉armv7拋棄iPhone5s之前的機(jī)型。重新運(yùn)行腳本./compile-ffmpeg.sh clean
和./compile-ffmpeg.sh all
-
再次編譯IJKMediaDemo.xcodeproj成功徒爹,選擇運(yùn)行IJKMediaDemo
選擇Online Samples即可播放M3U8
-
Demo運(yùn)行沒問題就可以拷貝資源文件到自己的項(xiàng)目中去播放了荚醒。也可單獨(dú)運(yùn)行IJKMediaPlayer.xcodeproj生成IJKMediaFramework.framework
- 模擬器運(yùn)行出來的只能在模擬器上運(yùn)行,真機(jī)調(diào)試運(yùn)行的只能在真機(jī)上運(yùn)行瀑焦,這里就需要合并framework
這是兩個不同的運(yùn)行環(huán)境腌且,需要合并IJKMediaFramework.framework下的IJKMediaFramework
運(yùn)行命令行:
lipo -create /Users/mac/Desktop/ijk/framework/phone/IJKMediaFramework /Users/mac/Desktop/ijk/framework/simulator/IJKMediaFramework -output /Users/mac/Desktop/ijk/framework/IJKMediaFramework
驗(yàn)證是否合并成功就是lipo中的IJKMediaFramework是否生產(chǎn)梗肝,還有就是使用lipo -info查看文件屬性吧算是會提示x86_64 arm64
arm64表示是真機(jī)的文件榛瓮,x86_64表示是模擬器支持的文件,顯示兩個就表示合并成功
注意區(qū)分debug版本還是release版本巫击,調(diào)試階段使用debug就行禀晓,這個切換在Xcode中product->scheme->edit scheme中更改
-
有了庫文件就可以拖到自己的工程中使用了,OC的項(xiàng)目導(dǎo)入
#import <IJKMediaFramework/IJKMediaFramework.h>
Build一下 success坝锰,然后導(dǎo)入視頻地址測試http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8
播放粹懒,編譯link錯誤
-
導(dǎo)入ijkplayer的readme中提到的相關(guān)庫
-
再次Build還是link錯誤,不過這次編程了__gxx_personality_v0…顷级,
- 這是還差一個庫以前是libstdc++.tbd凫乖,現(xiàn)在是
libc++.1.tbd
,導(dǎo)入即可;故事板中拉個uiview(顯示播放界面)帽芽、button(控制播放删掀、暫停)
#import "ViewController.h"
#import <IJKMediaFramework/IJKMediaFramework.h>
@interface ViewController ()
@property (atomic, retain) id <IJKMediaPlayback> player;
@property (weak, nonatomic) IBOutlet UIView *playView;
@property (weak, nonatomic) IBOutlet UIButton *playBtn;
@end
@implementation ViewController
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (![_player isPlaying]) {
[self.player prepareToPlay];
}
}
-(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURL *url = [NSURL URLWithString:@"http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8"];
_player = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:nil];
UIView *playerView = [_player view];
playerView.frame = self.playView.frame;
[self.view addSubview:playerView];
}
-(IBAction)clickedAction:(id)sender {
if (![_player isPlaying]) {
[self.player play];
[self.playBtn setTitle:@"Pause" forState:UIControlStateNormal];
}else {
[self.player pause];
[self.playBtn setTitle:@"Play" forState:UIControlStateNormal];
}
}
@end