直播推流之blibli和拉流LFLiveKit

來源:互聯網
上載者:User

標籤:技術分享   break   form   format   reg   nbsp   object   art   error   

執行上面操作後,匯入合成的拉流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;}

 

直播推流之blibli和拉流LFLiveKit

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.