發(fā)現(xiàn)大家都挺喜歡看關(guān)于視頻開(kāi)發(fā)的項(xiàng)目涝缝,于是也發(fā)一篇吧扑庞,個(gè)人經(jīng)驗(yàn)不足,有錯(cuò)的話請(qǐng)大家多多指教拒逮。開(kāi)始進(jìn)入視頻坑的朋友罐氨,自己得先好好看看AVPlayer,畢竟要先把基礎(chǔ)打扎實(shí)嘛滩援。相關(guān)基礎(chǔ)鏈接:
網(wǎng)絡(luò)播放器相關(guān)
http://blog.csdn.net/Matthew_Fan/article/category/1200896
HLS流媒體開(kāi)發(fā)
http://blog.csdn.net/sdvch/article/details/14047281
HLS 比較全的中文博客
http://blog.csdn.net/Matthew_Fan/article/category/1200896
蘋果 iOS 開(kāi)發(fā)文檔 (HLS)
https://developer.apple.com/streaming/
正文
但是急于做出一個(gè)demo交工栅隐,就簡(jiǎn)略的查了查攻略- -,發(fā)現(xiàn)B站的開(kāi)源項(xiàng)目ijkPlayer是一個(gè)很好借鑒的項(xiàng)目,趕緊下下來(lái)試試租悄,
鏈接:https://github.com/Bilibili/ijkplayer
具體怎么編譯就不一一細(xì)說(shuō)了谨究,自己參照一下文檔,這里我主要針對(duì)導(dǎo)入ijkplayer包并且使用做一些簡(jiǎn)單的說(shuō)明泣棋。
完成github上的步驟之后胶哲,我們打開(kāi)ios文件夾下的IJKMediaPlayer工程,發(fā)現(xiàn)他的output是一個(gè)framework包潭辈,那樣就輕松了
之后的內(nèi)容可以參考ijkdemo中的ijkMoviePlayerViewController實(shí)現(xiàn)調(diào)用播放器鸯屿,如果你不需要這么多東西也可以直接像我這樣簡(jiǎn)單寫:
ViewController
#import
@interfaceViewController : UIViewController
@property(atomic,strong) NSURL *url;
@property(atomic,retain)id player;
@property(weak,nonatomic)IBOutletUIView ? *PlayerView;
@property(weak,nonatomic)IBOutletUIButton ? *playButton;
然后就通過(guò)初試化一些基本設(shè)置就可以播放了:
1、url
2萎胰、PlayView
3碾盟、notification
4、prepareToPlay
簡(jiǎn)單把界面上的東西部署一下技竟,url等初始化
self.url = [NSURL ? URLWithString:@"http://live.hkstv.hk.lxdns.com/live/hks/playlist.m3u8"];
_player =[[IJKFFMoviePlayerController alloc] initWithContentURL:self.urlwithOptions:nil];
UIView *playerView = ? [_player view];
playerView.frame =self.PlayerView.frame;
playerView.autoresizingMask ? = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.PlayerView insertSubview:playerViewatIndex:1];
[_player ? setScalingMode:IJKMPMovieScalingModeAspectFill];
[self ? installMovieNotificationObservers];
別忘記了這個(gè)
[self.player prepareToPlay];
最后在你需要的地方調(diào)用播放等接口
[self.player play];
demo鏈接:http://download.csdn.net/detail/atomic123/9402481
希望能給大家?guī)?lái)幫助