在線視頻或直播(RTMP)--ijkplayer學習

最近公司要做直播這塊,經(jīng)過一番摸索,我學習了ijkplayer這個框架。

1.環(huán)境配置這塊就不再重復網(wǎng)上的例子很多,為大家推薦一篇講得相當詳細的文章:http://www.itdecent.cn/p/4f21af680c19
2.就講講具體的使用:

#import "ViewController.h"
#import <IJKMediaFramework/IJKFFMoviePlayerController.h>
@interface ViewController ()
@property(nonatomic,strong)IJKFFMoviePlayerController * player;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    IJKFFOptions *options = [IJKFFOptions optionsByDefault]; //使用默認配置
    NSURL * url = [NSURL URLWithString:@"rtmp://live.hkstv.hk.lxdns.com/live/hks"];
    self.player = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:options]; //初始化播放器,播放在線視頻或直播(RTMP)
    self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    self.player.view.frame = self.view.bounds;
    self.player.scalingMode = IJKMPMovieScalingModeAspectFit; //縮放模式
    self.player.shouldAutoplay = YES; //開啟自動播放
    
    self.view.autoresizesSubviews = YES;
    [self.view addSubview:self.player.view];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.player prepareToPlay];
}

-(void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self.player shutdown];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end

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

git上傳單個文件不能超過100M~ 所以我把這個從項目中剝離了出來 大家可以參考本文最上面的鏈接自己生成,或者可以私我,我直接發(fā)給你~


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容