直播推流之blibli和拉流LFLiveKit

执行上面操作后,导入合成的拉流blibli包到工程中,然后新建个播放控制器来设置播放

1.  播放的一些操作。

2. 高斯模糊。

3. 新建聊天控制器。

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self initPlayer];//添加播放器
    [self loadUI]; //添加高斯模糊
    [self loadChatVC]; //加载聊天控制器
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    [self installMovieNotificationObservers];

    [self.player prepareToPlay];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [self.player shutdown];
    [self removeMovieNotificationObservers];
}
- (void)setLives:(STRHotLive *)lives{
    _lives = lives;
}
- (void)initPlayer{
#ifdef DEBUG
    [IJKFFMoviePlayerController setLogReport:YES];
    [IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_DEBUG];
#else
    [IJKFFMoviePlayerController setLogReport:NO];
    [IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_INFO];
#endif

    IJKFFOptions *options = [IJKFFOptions optionsByDefault];

    self.player = [[IJKFFMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",_lives.streamAddr]] withOptions:options];
    self.player.view.frame = self.view.bounds;
    self.player.scalingMode = IJKMPMovieScalingModeAspectFit;
    self.player.shouldAutoplay = YES;
    [self.view addSubview:self.player.view];
}
- (void)loadUI{
    [self.view setBackgroundColor:STRCOLOR(0, 0, 0)];
    [self loadBlurImage];
}
- (void)loadChatVC{
    [self addChildViewController:self.chatVc];
    [self.view addSubview:self.chatVc.view];
    self.chatVc.delegate = self;
    WEAKSELF;
    [self.chatVc.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view);
    }];
}
- (void)loadBlurImage{

    UIImageView *blurImageV = [[UIImageView alloc] init];
    blurImageV.frame = self.view.bounds;
    [blurImageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",_lives.creator.portrait]] placeholderImage:[UIImage imageNamed:@"default_room"]];
    UIBlurEffect *blurE = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurE];
    effectView.frame = blurImageV.bounds;
    [blurImageV addSubview:effectView];
    [self.view addSubview:blurImageV];
    self.blurImageView = blurImageV;
}
#pragma mark --- delegate
- (void)chatLiveViewController:(STRChatLiveViewController *)chatVc didButtonClickWithSender:(UIButton *)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark --- noti
- (void)loadStateDidChange:(NSNotification*)notification
{
    //    MPMovieLoadStateUnknown        = 0,
    //    MPMovieLoadStatePlayable       = 1 << 0,
    //    MPMovieLoadStatePlaythroughOK  = 1 << 1, // Playback will be automatically started in this state when shouldAutoplay is YES
    //    MPMovieLoadStateStalled        = 1 << 2, // Playback will be automatically paused in this state, if started

    IJKMPMovieLoadState loadState = _player.loadState;

    if ((loadState & IJKMPMovieLoadStatePlaythroughOK) != 0) {
        NSLog(@"loadStateDidChange: IJKMPMovieLoadStatePlaythroughOK: %d\n", (int)loadState);
    } else if ((loadState & IJKMPMovieLoadStateStalled) != 0) {
        NSLog(@"loadStateDidChange: IJKMPMovieLoadStateStalled: %d\n", (int)loadState);
    } else {
        NSLog(@"loadStateDidChange: ???: %d\n", (int)loadState);
    }
}

- (void)moviePlayBackDidFinish:(NSNotification*)notification
{
    //    MPMovieFinishReasonPlaybackEnded,
    //    MPMovieFinishReasonPlaybackError,
    //    MPMovieFinishReasonUserExited
    int reason = [[[notification userInfo] valueForKey:IJKMPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];

    switch (reason)
    {
        case IJKMPMovieFinishReasonPlaybackEnded:
            NSLog(@"playbackStateDidChange: IJKMPMovieFinishReasonPlaybackEnded: %d\n", reason);
            break;

        case IJKMPMovieFinishReasonUserExited:
            NSLog(@"playbackStateDidChange: IJKMPMovieFinishReasonUserExited: %d\n", reason);
            break;

        case IJKMPMovieFinishReasonPlaybackError:
            NSLog(@"playbackStateDidChange: IJKMPMovieFinishReasonPlaybackError: %d\n", reason);
            break;

        default:
            NSLog(@"playbackPlayBackDidFinish: ???: %d\n", reason);
            break;
    }
}

- (void)mediaIsPreparedToPlayDidChange:(NSNotification*)notification
{
    NSLog(@"mediaIsPreparedToPlayDidChange\n");
}

- (void)moviePlayBackStateDidChange:(NSNotification*)notification
{
    //    MPMoviePlaybackStateStopped,
    //    MPMoviePlaybackStatePlaying,
    //    MPMoviePlaybackStatePaused,
    //    MPMoviePlaybackStateInterrupted,
    //    MPMoviePlaybackStateSeekingForward,
    //    MPMoviePlaybackStateSeekingBackward

    switch (_player.playbackState)
    {
        case IJKMPMoviePlaybackStateStopped: {
            NSLog(@"IJKMPMoviePlayBackStateDidChange %d: stoped", (int)_player.playbackState);
            break;
        }
        case IJKMPMoviePlaybackStatePlaying: {
            NSLog(@"IJKMPMoviePlayBackStateDidChange %d: playing", (int)_player.playbackState);
            break;
        }
        case IJKMPMoviePlaybackStatePaused: {
            NSLog(@"IJKMPMoviePlayBackStateDidChange %d: paused", (int)_player.playbackState);
            break;
        }
        case IJKMPMoviePlaybackStateInterrupted: {
            NSLog(@"IJKMPMoviePlayBackStateDidChange %d: interrupted", (int)_player.playbackState);
            break;
        }
        case IJKMPMoviePlaybackStateSeekingForward:
        case IJKMPMoviePlaybackStateSeekingBackward: {
            NSLog(@"IJKMPMoviePlayBackStateDidChange %d: seeking", (int)_player.playbackState);
            break;
        }
        default: {
            NSLog(@"IJKMPMoviePlayBackStateDidChange %d: unknown", (int)_player.playbackState);
            break;
        }
    }
    self.blurImageView.hidden = YES;
    [self.blurImageView removeFromSuperview];
}

#pragma mark Install Movie Notifications

/* Register observers for the various movie object notifications. */
-(void)installMovieNotificationObservers
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(loadStateDidChange:)
                                                 name:IJKMPMoviePlayerLoadStateDidChangeNotification
                                               object:_player];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:IJKMPMoviePlayerPlaybackDidFinishNotification
                                               object:_player];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(mediaIsPreparedToPlayDidChange:)
                                                 name:IJKMPMediaPlaybackIsPreparedToPlayDidChangeNotification
                                               object:_player];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackStateDidChange:)
                                                 name:IJKMPMoviePlayerPlaybackStateDidChangeNotification
                                               object:_player];
}

#pragma mark Remove Movie Notification Handlers

/* Remove the movie notification observers from the movie object. */
-(void)removeMovieNotificationObservers
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:IJKMPMoviePlayerLoadStateDidChangeNotification object:_player];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:IJKMPMoviePlayerPlaybackDidFinishNotification object:_player];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:IJKMPMediaPlaybackIsPreparedToPlayDidChangeNotification object:_player];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:IJKMPMoviePlayerPlaybackStateDidChangeNotification object:_player];
}
#pragma mark --- getters and setters
- (STRChatLiveViewController *)chatVc{
    if (_chatVc == nil) {
        _chatVc = [[STRChatLiveViewController alloc] init];
    }
    return _chatVc;
}
时间: 2024-12-29 10:36:54

直播推流之blibli和拉流LFLiveKit的相关文章

推流和拉流的概念以及RTMP和HLS协议

https://www.bbsmax.com/A/x9J2wZM56o/ 推流为将直播内容推送至服务器的过程:拉流为服务器已有直播内容,用指定地址进行拉取的过程. rtmp rtmp是Real Time Messaging Protocol(实时消息传输协议)的首字母缩写.该协议基于TCP,是一个协议族,包括RTMP基本协议及RTMPT/RTMPS/RTMPE等多种变种.RTMP是一种设计用来进行实时数据通信的网络协议,主要用来在Flash/AIR平台和支持RTMP协议的流媒体/交互服务器之间进

直播系统推拉流端技术

想要搭建网络视频直播系统就要明白视频直播的过程是什么样的,而直播流程可以分为采集.前处理.压缩编码.推流.拉流.解码.渲染播放这几个环节,其中涉及到推流端.拉流端和服务器三端的知识点,服务器方面的知识点很多,拓幻科技这里先简单说下推流端和拉流端的一些知识点,服务器方面可以先看我以前写的文章. 一. 推流端的四个环节1. 首先是采集环节:采集是指对图像和声音的采集,简单说就是能让网络视频直播系统和主播摄像头连起来,软件能获取到外界的音视频信息.然后是前处理阶段:这里也是俗称美颜的阶段,这要求我们在

直播系统搭建:拉流端的三个环节及服务器部署重点

拉流端的三个环节 1. 用户想看直播就要去服务器进行拉流,什么是拉流?你打开视频网站,点击视频,你点击视频和视频打开之间的时间段,就是你的客户端去向服务器请求拉流了,这一步要注意的是首屏开启时间,时间越短,观众越有可能被留下. 2. 有编码就要有解码,编码上会出现安卓适配问题,那解码上当然也会出现该问题,网络视频直播系统自带编解码程序的优势就在于它能够避免因手机机型不同,视频格式不同而产生的不同机型无法播放的情况. 3. 渲染环节交给手机就可以了,播放之后用户就可以进行观看了. 直播系统源码搭建

绝对独创---关于直播(推流-拉流-服务器搭建)

1.公司有风声要做直播,赶好这段有时间,自己研究了一下.其实走过的弯路比较多,后来在拉流/推流/服务器搭建都完成之后,思路变得很清晰. 2.首先从服务器搭建说起,关于三种主流的HLS/RTMP/FLV,这里我使用的是RTMP,关于其中的切换,我们需要看一下ngnix的配置文件的相关参数文档. 我使用的是ngnix+rtmp,也就是本地搭建ngnix服务器,另外在ngnix服务器上添加了rtmp的模块.闭门造车容易猝死,我参考的是简书上的,请移步:http://www.jianshu.com/p/

【转】直播流程,视频推流,视频拉流,简介,SMTP、RTMP、HLS、 PLPlayerKit

原:https://www.cnblogs.com/baitongtong/p/11248966.html 1 .音视频处理的一般流程: 数据采集→数据编码→数据传输(流媒体服务器) →解码数据→播放显示1.数据采集:摄像机及拾音器收集视频及音频数据,此时得到的为原始数据涉及技术或协议:摄像机:CCD.CMOS拾音器:声电转换装置(咪头).音频放大电路2.数据编码:使用相关硬件或软件对音视频原始数据进行编码处理(数字化)及加工(如音视频混合.打包封装等),得到可用的音视频数据涉及技术或协议:编码

直播-拉流和推流概述 转载

拉流(播放): 根据协议类型(如RTMP.RTP.RTSP.HTTP等),与服务器建立连接并接收数据: 解析二进制数据,从中找到相关流信息: 根据不同的封装格式(如FLV.TS)解复用(demux): 分别得到已编码的H.264视频数据和AAC音频数据: 使用硬解码(对应系统的API)或软解码(FFMpeg)来解压音视频数据: 经过解码后得到原始的视频数据(YUV)和音频数据(AAC): 因为音频和视频解码是分开的,所以我们得把它们同步起来,否则会出现音视频不同步的现象,比如别人说话会跟口型对不

iOS简单直播实现(三:IJKMediaFramework拉流)

推流完成后,需要拉流才能进行完整的直播.拉流我们采用的也是一个开源的第三方库IJKMediaFramework. 这个库本质是一个播放器,能播放flv格式的播放器.用起来和ios自带的AVPlayer很相似. 实现功能:1.拉流播放.2.监听. 一.创建占位图和卡顿占位动效,代码如下: //直播前的占位图片- (UIImageView *)placeHolderView { if (!_placeHolderView) { _placeHolderView = [[UIImageView all

IJKPlayer集成直播拉流播放

iOS端集成ijkplayer实现直播播放 前言 ijkplayer框架是专门用来做 视频直播 的开源框架,基于ffmpeg,同时支持 Android 和 iOS 平台. 对于 App 中的直播功能,如果我们成功集成ijkplayer ,那么就算完成一半的工程了.接下来,只要获取到 拉流 URL,就能实现视频直播功能了. 但是初次集成这个框架,对于新手还是有一定难度的. 本篇主要介绍如何快速集成 ijkplayer 框架. 最终效果.gif 一.下载 ijkplayer 1.下载 ijkplay

EasyRTMP获取H.264实时流并转化成为RTMP直播推流之EasyRTMP-iOS如何处理H264关键帧和SPS、PPS数据的

EasyRTMP是结合了多种音视频缓存及网络技术的一个rtmp直播推流端,包括:圆形缓冲区(circular buffer).智能丢帧.自动重连.rtmp协议等等多种技术,能够非常有效地适应各种平台(Windows.Linux.ARM.Android.iOS),各种网络环境(有线.wifi.4G),以及各种情况下的直播恢复(服务器重启.网络重启.硬件设备重启). ? 提出问题: EasyRTMP-iOS如何处理H264关键帧和SPS.PPS数据? 分析问题: 对于编码后的H264数据的处理在H2