记录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过错
- 导入ijkplayer的readme中提到的相关库
- 再次Build仍是link过错,不过这次编程了__gxx_personality_v0…,
- 这是还差一个库以前是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
- 综上所述,只需有合成好的framework,把它拖到工程当中,Link相关库即可播映,请参阅OCDemo或SwiftDemo
如有问题,欢迎反馈,谢谢!
作者:long弟弟
链接:www.jianshu.com/p/683ccc09d…
来历:简书
著作权归作者所有。商业转载请联络作者获得授权,非商业转载请注明出处。
补充
1、编译真机时报错
IJKMediaPlayer.xcodeproj The linked library 'libavformat.a' is missing one or more architectures required by this target: armv7.
处理: 在Target – Build Settings – Excluded Architectures增加如下:
EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))
2、兼并framework时 报错
IJKMediaFramework have the same architectures (arm64) and can't be in the same fat output file
处理: 在Target – Build Settings – Excluded Architectures增加如下:
- 点击右侧加号,增加Any iOS Simulator SDK
- 在Any iOS Simulator SDK 后面增加arm64。 这样编译出来的包中就不会包括arm64了。
3、进入Xcode/DerivedData/…/Products目录,运用 lipo -create 真机途径 模拟器途径 -output 真机途径
将二者framework兼并输出: cd /Users/lf/Library/Developer/Xcode/DerivedData/IJKMediaDemo-cvfdngeaecgjswfsdaurcwyraeah/Build/Products
lipo -create Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework -output /Users/lf/Desktop/iOS/IJKMediaFramework
通过lipo -info IJKMediaFramework
命令查看framework
支持情况。可看到现在这个真机、模拟器都是支持的。
lipo -info /Users/lf/Desktop/iOS/IJKMediaFramework
将兼并后的framework拷贝到Release-iphoneos/IJKMediaFramework.framework
真机文件夹中掩盖
4、将兼并后的真机IJKMediaFramework.framework
(Release-iphoneos/IJKMediaFramework.framework)增加到咱们项目中来
5、增加一些依靠的动态库。(Xcode13不需要增加了)
AudioToolbox.framework
AVFoundation.framework
CoreGraphics.framework
CoreMedia.framework
CoreVideo.framework
libbz2.tbd
libz.tbd
MediaPlayer.framework
MobileCoreServices.framework
OpenGLES.framework
QuartzCore.framework
UIKit.framework
VideoToolbox.framework
6、样例代码
import UIKit
import IJKMediaFramework
class PhoneNumberLoginVC: BaseVC {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// 开始播映
if !playerVC.isPlaying() {
playerVC.prepareToPlay()
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// 封闭播映器
playerVC.shutdown()
}
override func initSubViews() {
super.initSubViews()
view.addSubview(playerVC.view)
playerVC.view.snp.makeConstraints { make in
make.edges.equalTo(view)
}
}
lazy var playerVC: IJKFFMoviePlayerController = {
let ijkFFOptions = IJKFFOptions.byDefault()
// 视频源地址
// 美国1
// let url = URL(string: "rtmp://media3.scctv.net/live/scctv_800")
// 中东
let url = URL(string: "rtmp://ns8.indexforce.com/home/mystream")
// 韩国朝鲜日报
// let url = URL(string: "rtmp://mobliestream.c3tv.com:554/live/goodtv.sdp")
let vc = IJKFFMoviePlayerController.init(contentURL: url, with: ijkFFOptions!)
// 缩放形式
vc?.scalingMode = .aspectFit
// 敞开自动播映
vc?.shouldAutoplay = true
return vc!
}()
}