美文网首页iOS 开发相关小食
iOS SGPlayer VR直播框架

iOS SGPlayer VR直播框架

作者: Yuency | 来源:发表于2019-03-20 16:10 被阅读22次

前言:

1、什么时候突然又要我弄VR直播了。真的是无解。
2、直播这个东西嘛,当然是去找个好的框架直接用。
3、我向来认为,使用别人的框架,对技术积累并无多大作用。
4、本篇记录一下我这次集成进来的VR直播框架
5、我再也不想碰VR直播框架了

代码地址:
链接:https://pan.baidu.com/s/12GpLFUpiMTKUDynQ1F3BVA 密码:2v8a
我比较喜欢代码拉下来就能跑的。里面的Framework 比较大,git不让传。

让我们开始吧!
Let's get start !
さ、始めよう!

效果图

效果图

第 1 步 拜访原作者

1、使用git把工程目录拷贝下来
2、进入到 SGPlayer 文件夹
3、执行脚本 compile-build.sh

第三步中执行脚本之后会生成.a库,后面用到,可以参阅原作者的说明。

原作者的代码地址: https://github.com/libobjc/SGPlayer
中文版说明地址:https://github.com/libobjc/SGPlayer/blob/master/documents/README-chs.md

git clone https://github.com/libobjc/SGPlayer.git
cd SGPlayer
sh compile-build.sh

第 2 步 我们先来看一下

如下图所示,被圈起来的地方就是我们需要调整的地方。图中的
SGPlatform.framework 和 SGPlayer.framework 都显示成红色,这是没有编译成功的,编译成功之后,就会变成白色。


结构.png

第 3 步 更改设置

我们分别选中 SGPlatform 和 SGPlayer 更改配置,把 build configuration 改成 release

改动一.png 改动二.png

第 4 步 编译framework

我们选中 SGPlayer 然后在后面的 分别选择 真机(generic iOS device) 和 模拟器(随便选一个) 按下 Command + B 编译,SGPlatform 也做相同的处理。

编译.png

第 5 步 寻找周杰伦

我们在编译完成的framework上面右键,“show in finder”。打开framework位置。

寻找周杰伦.png

第 6 步 合并

1、使用命令行,cd 之后直接把文件夹拖放到命令行里面,然后按下回车,执行下面两个命令,合并

lipo -create Release-iphoneos/SGPlatform.framework/SGPlatform Release-iphonesimulator/SGPlatform.framework/SGPlatform -output SGPlatform

lipo -create Release-iphoneos/SGPlayer.framework/SGPlayer Release-iphonesimulator/SGPlayer.framework/SGPlayer -output SGPlayer

操作示意图


合并.png

第 7 步 替换.a文件

替换1.png 替换2.png

第 8 步 上面做完之后,就得到了完整的支持真机和模拟器的framework。

最终结果.png

第 9 步 集成

新建iOS工程, 把上面的两个包拖进项目,并且在添加以下依赖

  • SGPlayer.framework
  • SGPlatform.framework Optional
  • CoreMedia.framework
  • AudioToolBox.framework
  • VideoToolBox.framework
  • libiconv.tbd
  • libbz2.tbd
  • libz.tbd
新建工程.png

并且添加第一步中编译出来的.a文件

导入编译.a.png

第 10 步 测试代码


#import "ViewController.h"
#import <SGPlayer/SGPlayer.h>
#import <AVKit/AVKit.h>

@interface ViewController ()

@property (nonatomic, strong) SGPlayer *player;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 加上这句话,否则没有声音
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    
    self.player = [SGPlayer player];
    
    // 注册事件通知
    [self.player registerPlayerNotificationTarget:self stateAction:@selector(stateAction:) progressAction:@selector(progressAction:) playableAction:@selector(playableAction:) errorAction:@selector(errorAction:)];
    
    // 视频画面点击事件
    __weak typeof(self) weakself = self;
    [self.player setViewTapAction:^(SGPlayer * _Nonnull player, SGPLFView * _Nonnull view) {
        NSLog(@"player display view did click!");
        [weakself.player play];
    }];
    
    [self.view insertSubview:self.player.view atIndex:0];
    
    NSString *live = @"rtmp://58.200.131.2:1935/livetv/hunantv";
    NSURL *u = [NSURL URLWithString:live];
    [self.player replaceVideoWithURL:u videoType:SGVideoTypeVR];
    
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.player.view.frame = self.view.bounds;
}

- (void)stateAction:(NSNotification *)notice{
}
- (void)progressAction:(NSNotification *)notice{
}
- (void)playableAction:(NSNotification *)notice{
}
- (void)errorAction:(NSNotification *)notice{
}

@end

第 11 步 Command + R

相关文章

网友评论

    本文标题:iOS SGPlayer VR直播框架

    本文链接:https://www.haomeiwen.com/subject/tmctvqtx.html