程序员@IT·互联网iOS Developer

iOS基于ijkplayer的直播

2017-02-26  本文已影响575人  星星编程

“你会做直播吗?”。也许在面试中面试官会经常这么问。不过你看了这篇文章,你就可以非常自信地说“我会,我可以做!”。该Demo录屏视频地址:http://t.cn/RiUQLoP ,欢迎查看!

首页1.jpg 首页2.jpg 直播.jpg 我的.jpg

一、 下载ijkplayer,GitHub地址:https://github.com/Bilibili/ijkplayer
打开ijkplayer-master文件目录如下:

ijkplayer-master.png
按照这篇文章http://www.jianshu.com/p/1f06b27b3ac0 一步一步集成IJKMediaFramework.framework并导入以下系统库:
AudioToolbox.framework
CoreGraphics.framework
CoreMedia.framework
CoreVideo.framework
libbz2.tbd
libz.tbd
MediaPlayer.framework
MobileCoreServices.framework
OpenGLES.framework
QuartzCore.framework
VideoToolbox.framework

二、设置播放直播

  IJKFFOptions *options = [IJKFFOptions optionsByDefault];

  [options setPlayerOptionIntValue:1  forKey:@"videotoolbox"];

  [options setPlayerOptionIntValue:29.97 forKey:@"r"];

  [options setPlayerOptionIntValue:512 forKey:@"vol"];

  IJKFFMoviePlayerController *moviePlayer = [[IJKFFMoviePlayerController alloc] initWithContentURLString:_curModel.flv withOptions:options];

  moviePlayer.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);

  moviePlayer.scalingMode = IJKMPMovieScalingModeAspectFill;

  moviePlayer.shouldAutoplay = NO;
    
  moviePlayer.shouldShowHudView = NO;
            
  [self.contentView  addSubview:moviePlayer.view];
            
  [moviePlayer prepareToPlay];

三、进行录播

[[LFLiveSession alloc] initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:[LFLiveVideoConfiguration defaultConfigurationForQuality:LFLiveVideoQuality_Medium2] liveType:LFLiveRTMP];

四、直播的功能的实现很简单,主要是细节问题。如聊天、点赞、弹幕、送小礼物等等。直播由于太火了,所以也出现了很多好的直播框架,这篇文章简述了几个直播框架还不错(http://www.jianshu.com/p/5ad5b68606bb ),非常值得学习。

如有需要该项目源码的,记得打赏哦。

上一篇下一篇

猜你喜欢

热点阅读