iOS音频、视频、直播相关iOS 视频直播视频直播

ios在线直播-->基于ijkplayer框架的进一步学习

2016-06-18  本文已影响1953人  Hither

在上一片文章中简单介绍了ijkplayer这个框架以及给出了一个例子。今天是继续深入学习ijkplayer这个框架的一天。😀😀😀

大家看看效果:

这个框架还是用的上一篇文章的 ,直接顺手拿过来。

看看整体的项目结构:

(1)还是按照习惯的做法,将UITableView的dataSource和delegate分离出来,方便自己写代码和以后的维护。

在delegate里面实现了列表滚动的3D动画效果:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);
    [UIView animateWithDuration:1 animations:^{
        cell.layer.transform = CATransform3DMakeScale(1, 1, 1);
    }];
}

(2)屏幕滚动 导航栏若隐若现

这里我使用KVO实现这个效果:

注册:
[_dataTableView addObserver: self forKeyPath: @"contentOffset" options: NSKeyValueObservingOptionNew context: nil];

实现的方法:
//KVO监听屏幕滚动
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
    UIPanGestureRecognizer* pan = _dataTableView.panGestureRecognizer;
    //获取到拖拽的速度 >0 向下拖动 <0 向上拖动
    CGFloat velocity = [pan velocityInView:_dataTableView].y;
    
    if (velocity<-5) {
        //向上拖动,隐藏导航栏
        [self.navigationController setNavigationBarHidden:true animated:true];
    }
    else if (velocity>5) {
        //向下拖动,显示导航栏
        [self.navigationController setNavigationBarHidden:false animated:true];
    }
    else if(velocity==0){
        //停止拖拽
    }
}

(3)讲讲播放

初始化player对象,并完成相关的设置

self.url = [NSURL URLWithString:_liveUrl];
_player = [[IJKFFMoviePlayerController alloc] initWithContentURL:self.url withOptions:nil];

注册通知&&移除通知

注册:
- (void)installMovieNotificationObservers {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(loadStateDidChange:)
                                                 name:IJKMPMoviePlayerLoadStateDidChangeNotification
                                               object:_player];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackFinish:)
                                                 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];
    
}
移除:
- (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];
}

Demo地址:https://github.com/hejintaochenxin/blue

注意下:因为git上传单个文件不能超过100M~ 所以我把这个从项目中剥离了出来 大家可以参考本文最上面的链接自己生成,或者可以私我,我直接发给你~你只需要把这个直接拖入项目就可以了~

在这里给大家推荐一个现在很牛叉的框架:SmarterStreaming

https://github.com/daniulive/SmarterStreaming

- 集成的时候需要注意:
(1)真机测试
(2)
1. 编译时找不到 libSmartPlayerSDK.a 时,请先到 SmartiOSPlayer/SmartiOSPlayer 目录, 解压libSmartPlayerSDK.zip.
2. 编译时找不到 libSmartPublisherSDK.a 时,请先到 SmartiOSPublisher/SmartiOSPublisher/libs 目录, 解压libSmartPublisherSDK.zip.
上一篇 下一篇

猜你喜欢

热点阅读