记录ijkplayer从一无所知到播放这个流程
-
先cd到你喜爱的目录下
-
Build iOS
执行git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios
克隆ijkplayer-ios -
cd到ijkplayer-ios文件夹下创建新分支并切换过去
git checkout -B latest k0.8.8
-
分支创建完后运行脚本
./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
发现问题就在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,并执行
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all
其实,在执行./compile-ffmpeg.sh all
的时候已经报错了,只是选择了忽略
现在,删掉armv7抛弃iPhone5s之前的机型。重新运行脚本./compile-ffmpeg.sh clean
和./compile-ffmpeg.sh all
-
再次编译IJKMediaDemo.xcodeproj成功,选择运行IJKMediaDemo
选择Online Samples即可播放M3U8 -
Demo运行没问题就可以拷贝资源文件到自己的项目中去播放了。也可单独运行IJKMediaPlayer.xcodeproj生成IJKMediaFramework.framework
模拟器运行出来的只能在模拟器上运行,真机调试运行的只能在真机上运行,这里就需要合并framework
这是两个不同的运行环境,需要合并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是否生产,还有就是使用lipo -info查看文件属性吧算是会提示x86_64 arm64
arm64表示是真机的文件,x86_64表示是模拟器支持的文件,显示两个就表示合并成功
注意区分debug版本还是release版本,调试阶段使用debug就行,这个切换在Xcode中product->scheme->edit scheme中更改
有了库文件就可以拖到自己的工程中使用了,OC的项目导入
#import <IJKMediaFramework/IJKMediaFramework.h>
Build一下 success,然后导入视频地址测试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)
- 导入ijkplayer的readme中提到的相关库
![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,现在是
libc++.1.tbd
,导入即可;故事板中拉个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弟弟
链接://www.greatytc.com/p/683ccc09d4ad
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。