今天的計劃是先做一個播放器逸月。網(wǎng)上找到這個框架PLPlayerKit。
PLPlayerKit 是一個適用于 iOS 的音視頻播放器 SDK镀赌,可高度定制化和二次開發(fā)油宜,特色是支持 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.
關(guān)鍵代碼:
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;//設(shè)置代理虏缸,可以監(jiān)聽播放器狀態(tài)
self.player.delegateQueue=dispatch_get_main_queue();
self.player.backgroundPlayEnable=NO;
[[AVAudioSessionsharedInstance]setCategory:AVAudioSessionCategoryPlaybackerror:nil];
[self.viewaddSubview:self.player.playerView];//加入當(dāng)前視圖
[self.player play];//開始播放
最后炫一下效果
別說我是土豪用4G網(wǎng)絡(luò)鲫懒,因為公司把視頻流屏蔽了。刽辙。窥岩。
明天繼續(xù),開始用nginx搭建服務(wù)器扫倡,嘗試做推流谦秧。