IOS每日学习7.26如何开发一款直播APP(1)

今天的计划是先做一个播放器。网上找到这个框架PLPlayerKit

PLPlayerKit 是一个适用于 iOS 的音视频播放器 SDK,可高度定制化和二次开发,特色是支持 RTMP, HTTP-FLV 和 HLS 直播流媒体播放。

github地址:https://github.com/pili-engineering/PLPlayerKit

通过cocoapods集成,命令如下:

target "VideoPlayerDemo" do

pod 'PLPlayerKit'

end 

VideoPlayerDemo是本次播放器工程名字,下载过程大概是这样子的:

Analyzing dependencies

Downloading dependencies

Installing HappyDNS (0.3.9)

Installing PLPlayerKit (2.2.2)

Installing pili-librtmp (1.0.3.1)

Generating Pods project

Integrating client project

[!] Please close any current Xcode sessions and use `VideoPlayerDemo.xcworkspace` for this project from now on.

Sending stats

Pod installation complete! There is 1 dependency from the Podfile and 3 total

pods installed.

下载完之后大概是这个样子:



注意:这里不需要引用任何的framework.

关键代码:

PLPlayerOption*option = [PLPlayerOptiondefaultOption];

[optionsetOptionValue:@10forKey:PLPlayerOptionKeyTimeoutIntervalForMediaPackets];

NSString*urlStr=[self.contentDictvalueForKey:@"url"];//要播放的地址,支持HLS和RTMP

NSURL*url=[NSURLURLWithString:urlStr];

self.player= [PLPlayerplayerWithURL:urloption:option];

self.player.delegate=self;//设置代理,可以监听播放器状态

self.player.delegateQueue=dispatch_get_main_queue();

self.player.backgroundPlayEnable=NO;

[[AVAudioSessionsharedInstance]setCategory:AVAudioSessionCategoryPlaybackerror:nil];

[self.viewaddSubview:self.player.playerView];//加入当前视图

[self.player play];//开始播放



最后炫一下效果

别说我是土豪用4G网络,因为公司把视频流屏蔽了。。。

明天继续,开始用nginx搭建服务器,尝试做推流。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容