直播云

  • 直播云 > SDK 下载 > 播放端 >QPlayer2 iOS端 > 基于 Core 的 QPlayer2 接入指南 > 快速开始

    快速开始

    最近更新时间: 2022-09-27 15:58:03

    快速开始

    基于 qplayer2-core 的播放器使用

    导入头文件

    #import <qplayer2_core/QPlayerContext.h>
    #import <qplayer2_core/RenderView.h>
    #import <qplayer2_core/QIOSCommon.h>
    

    初始化

        NSString *documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];  
        self.playerContext =  [[QPlayerContext alloc]initPlayerAPPVersion:nil localStorageDir:documentsDir logLevel:LOG_VERBOSE];
    

    设置显示视图

         _myRenderView = [[RenderView alloc]initWithFrame:CGRectMake(0, _topSpace, PLAYER_PORTRAIT_WIDTH, PLAYER_PORTRAIT_HEIGHT)];
        [_myRenderView attachPlayerContext:self.playerContext];
        [self.view addSubview:_myRenderView];
    

    播放

        NSMutableArray<QStreamElement *> *arr = [[NSMutableArray alloc]init];
        QStreamElement * element = [[QStreamElement alloc]init];
        element.url = @"http://demo-videos.qnsdk.com/qiniu-1080p.mp4";
        element.userType = @"";
        element.urlType = QURL_TYPE_QAUDIO_AND_VIDEO;
        element.isSelected = YES;
        element.quality = 1080;
        [arr addObject:element];
        QMediaModel *model = [[QMediaModel alloc] init];
        model.streamElements = arr;
        model.isLive = NO;
        [self.playerContext.controlHandler playMediaModel:model startPos:0];
    

    销毁

       [self.playerContext.controlHandler playerRelease];       
       self.playerContext = nil;
    
    以上内容是否对您有帮助?
  • Qvm free helper
    Close