0%

集成 ijkplayer

前言

Mac 上推 rtmp 流, iOS 集成 ijkPlayer 播放。

步骤

  1. 先把 ijkPlayerDemo 跑起来再说

    按照 README 里的 Before Build

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios
    cd ijkplayer-ios
    git checkout -B latest k0.8.8

    ./init-ios.sh

    # 编译openssl 以支持 https, 不需要可以跳过
    ./init-ios-openssl.sh
    echo 'export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-openssl"' >> ../config/module.sh
    ./compile-openssl.sh all

    cd ios
    ./compile-ffmpeg.sh clean
    ./compile-ffmpeg.sh all

    ./compile-ffmpeg.sh all 时会报错

    1
    2
    ./libavutil/arm/asm.S:50:9: error: unknown directive
    .arch armv7-a

    解决办法 issues

  2. 打包静态库 IJKMediaFramework

    打开 IJKMediaPlayer.xcodeproj ,scheme 选择 IJKMediaFramework——Run——Info——Build Configuration——Release ,选择模拟器 build,切真机再 build 会报错

    1
    'armv7/avconfig.h' file not found

    注释掉这行后 build 成功。

    项目目录 Products 下 右键 IJKMediaFramework.framework——Show in Finder ,在 Release-iphoneos 所在路径下合并真机和模拟器共用的静态库

    1
    lipo -create Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework -output IJKMediaFramework

    将生成的 IJKMediaFramework 替换路径 Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework

  3. 新建工程后添加 IJKMediaFramework.framework 和系统依赖库,支持 https 的话还要添加 libcrypto.alibssl.a 。运行报错

    1
    "operator delete(void*)", referenced from:

    添加系统依赖库 libc++.tbd 解决

  4. 使用 ijkPlayer

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    var player: IJKFFMoviePlayerController!

    override func viewDidLoad() {
    super.viewDidLoad()

    player = IJKFFMoviePlayerController.init(contentURL: URL.init(string: "rtmp://192.168.69.21:1990/liveApp")!, with: IJKFFOptions.byDefault())
    player.view.frame = CGRect(x: 0, y: 0, width: 300, height: 300)
    view.addSubview(player.view)
    player.prepareToPlay()
    player.play()
    // Do any additional setup after loading the view, typically from a nib.
    }

    Mac 推流真机播放