記錄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)建完后運行腳本
./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文件夾晒夹,運行腳本
./compile-ffmpeg.sh clean
和./compile-ffmpeg.sh all
- 編譯IJKMediaDemo.xcodeproj可能會報錯
'libavformat/avformat.h' file not found
發(fā)現(xiàn)問題就在issues里找答案壹店,參考#1251
1.進入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
其實,在執(zhí)行./compile-ffmpeg.sh all
的時候已經(jīng)報錯了耍攘,只是選擇了忽略
現(xiàn)在榕栏,刪掉armv7拋棄iPhone5s之前的機型。重新運行腳本./compile-ffmpeg.sh clean
和./compile-ffmpeg.sh all
-
再次編譯IJKMediaDemo.xcodeproj成功蕾各,選擇運行IJKMediaDemo
選擇Online Samples即可播放M3U8 -
Demo運行沒問題就可以拷貝資源文件到自己的項目中去播放了扒磁。也可單獨運行IJKMediaPlayer.xcodeproj生成IJKMediaFramework.framework
模擬器運行出來的只能在模擬器上運行,真機調(diào)試運行的只能在真機上運行式曲,這里就需要合并framework
這是兩個不同的運行環(huán)境渗磅,需要合并IJKMediaFramework.framework下的IJKMediaFramework
運行命令行:
lipo -create /Users/mac/Desktop/ijk/framework/phone/IJKMediaFramework /Users/mac/Desktop/ijk/framework/simulator/IJKMediaFramework -output /Users/mac/Desktop/ijk/framework/IJKMediaFramework
驗證是否合并成功就是lipo中的IJKMediaFramework是否生產(chǎn),還有就是使用lipo -info查看文件屬性吧算是會提示x86_64 arm64
arm64表示是真機的文件检访,x86_64表示是模擬器支持的文件始鱼,顯示兩個就表示合并成功
注意區(qū)分debug版本還是release版本,調(diào)試階段使用debug就行脆贵,這個切換在Xcode中product->scheme->edit scheme中更改
有了庫文件就可以拖到自己的工程中使用了医清,OC的項目導(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錯誤
![image](//upload-images.jianshu.io/upload_images/3115781-bcd3f01efa8a7c9b.png?imageMogr2/auto-orient/strip|imageView2/2/w/700/format/webp)
- 導(dǎo)入ijkplayer的readme中提到的相關(guān)庫
![image](//upload-images.jianshu.io/upload_images/3115781-60e2de39702554f9.png?imageMogr2/auto-orient/strip|imageView2/2/w/942/format/webp)
- 再次Build還是link錯誤会烙,不過這次編程了__gxx_personality_v0…,
![image](//upload-images.jianshu.io/upload_images/3115781-753b520888466ffb.png?imageMogr2/auto-orient/strip|imageView2/2/w/614/format/webp)
- 這是還差一個庫以前是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
作者:long弟弟
鏈接:http://www.reibang.com/p/683ccc09d4ad
來源:簡書
著作權(quán)歸作者所有氓仲。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán)水慨,非商業(yè)轉(zhuǎn)載請注明出處。