1. 準備工作
安裝homebrew、git等,google 一下一堆傻瓜式流程指導,自行搜索.
2. 獲取 ijkplayer 源碼
cd 到自己想要保存的文件中,執(zhí)行一下命令
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios
cd ijkplayer-ios
git checkout -B latest k0.8.8
3. 獲取 ffmpeg 并初始化
執(zhí)行腳本獲取 ffmpeg ,輸入一下命令
cd ..
./init-ios.sh
4. 添加 https 支持
# 獲取 openssl 并初始化
./init-ios-openssl.sh
cd ios
# 在模塊文件中添加一行配置 以啟用 openssl 組件
echo 'export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-openssl"' >> ../config/module.sh
./compile-ffmpeg.sh clean
5. 編譯 ffmpeg
如下:
# 如果下一步提示錯誤`xcrun: error: SDK "iphoneos" cannot be located`, 請執(zhí)行`sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/`, 再重新執(zhí)行下一步
# 編譯openssl, 如果不需要https可以跳過這一步
./compile-openssl.sh all
# 編譯ffmpeg
./compile-ffmpeg.sh all
執(zhí)行最后一步,如果出現(xiàn)錯誤如下:
./libavutil/arm/asm.S:50:9: error: unknown directive
.arch armv7-a
^
make: *** [libavcodec/arm/aacpsdsp_neon.o] Error 1
是因為最新的 Xcode 已經(jīng)弱化了對 32 位的支持, 解決方法:
在 compile-ffmpeg.sh 中刪除 armv7 ,也就是修改 FF_ALL_ARCHS_IOS8_SDK="armv7 arm64 i386 x86_64" 為 FF_ALL_ARCHS_IOS8_SDK="arm64 i386 x86_64
然后重新執(zhí)行 ./compile-ffmpeg.sh all
6. 打開IJKMediaPlayer項目
添加 openssl 相關依賴:
選擇 Targets ——> IJKMediaFrameworkWithSSL ——> General ——> Linked Frameworks and Libraries ,選擇 Add Other... , 然后在 ijkplayer-ios 目錄下(也可能是別的名字)的 ios —— build —— universal —— lib 中,選中 libcrypto.a 和 libssl.a 文件,添加進去
如圖:


7. 打包 framework
1)選擇 Xcode 上方導航欄中的 Product ——> Scheme ——> Edit Scheme..., 打開后選擇 Run ——> Info ——> Build Configuration,將 Debug 改為 Release。
如圖:

2)Cmd + b 直接運行,會報錯 avconfig.h 文件找不到,這時候去一下路徑找到 avconfig.h 文件,如:
~/Desktop/ijkplayer-ios/ios/build/universal/include/libavutil
打開 avconfig.h ,注釋掉
include "armv7/avconfig.h"
如圖:

3)Cmd + b 再運行,又報錯 config.h 文件找不到,去
~/Desktop/ijkplayer-ios/ios/build/universal/include/libffmpeg
中打開 config.h , 同上注釋掉
include "armv7/avconfig.h"
4)Cmd + b 再運行,還報錯... ld: symbol(s) not found for architecture armv7, 也就是 armv7 不支持,去
TARGETS ——> IJKMediaFrameworkWithSSL ——> Build Settings ——> Valid Architecutres
中,刪掉其中的 armv7、armv7s
5)Cmd + b 再運行,Success ??!! 選擇真機(Generic iOS Device),再運行,Success !!! 這時候,項目的 Products 文件目錄下就生成了 模擬器的framework (Release-iphonesimulator) 和 真機的framework(Release-iphoneos),這里右鍵點擊 Xcode — Products 下的 IJKMediaFrameworkWithSSL.framework ,show in finder 就能直接到。
8. 合成 framework
用終端到當前生成的 framework 目錄下,執(zhí)行以下命令
lipo -create Release-iphoneos/IJKMediaFrameworkWithSSL.framework/IJKMediaFrameworkWithSSL Release-iphonesimulator/IJKMediaFrameworkWithSSL.framework/IJKMediaFrameworkWithSSL -output IJKMediaFrameworkWithSSL
將生成的 IJKMediaFrameworkWithSSL 替換掉 Release-iphoneos/IJKMediaFrameworkWithSSL.framework 文件下的 IJKMediaFrameworkWithSSL,就 OK 啦。
9. 將生成的 framework 導入到所需工程中
1)直接將 IJKMediaFramework.framework 拖入到工程中即可,注意記得勾選 Copy items if needed 和 對應的 target。
2)然后添加相關依賴
libc++.tbd ( 編譯器選 gcc 的請導入 libstdc++.tbd )
libz.tbd
libbz2.tbd
AudioToolbox.framework
UIKit.framework
CoreGraphics.framework
AVFoundation.framework
CoreMedia.framework
CoreVideo.framework
MediaPlayer.framework
MobileCoreServices.framework
OpenGLES.framework
QuartzCore.framework
VideoToolbox.framework
3)在相應文件中導入 #import <IJKMediaFrameworkWithSSL/IJKMediaPlayer.h>
即可使用 IJKMediaPlayer 了
4)如果運行程序報 image not found 錯誤 ,需在工程對應 TARGETS —— General —— Embedded Binaries 中添加 IJKMediaFrameworkWithSSL.framework 即可.