直播云

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

    快速开始

    最近更新时间: 2022-12-12 16:48:55

    快速开始

    基于 qplayer2-core 的播放器使用

    导入头文件

    #import <qplayer2_core/qplayer2_core.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];
    

    播放

        //参数为该视频师傅是直播,YES为是直播,NO为不是直播
        QMediaModelBuilder *modleBuilder = [[QMediaModelBuilder alloc] initWithIsLive:NO];
        [modleBuilder addStreamElementWithUserType:@""                                                     //预留字段,可以为空
                                 urlType:QURL_TYPE_QAUDIO_AND_VIDEO                      //资源的类型,这里的url对应的资源是音视频
                                 url:@"http://demo-videos.qnsdk.com/qiniu-1080p.mp4"     //播放地址
                                 quality:1080                                            //清晰度数值标记为1080
                                 isSelected:YES                                          //是否是默认元素,默认元素是指,起播的时候默认会播放这个元素
                                 backupUrl:@""                                            //备用地址
                                 referer:@""                                              //http/https 协议的地址 支持该属性              
                                 renderType:QPLAYER_RENDER_TYPE_PLANE];                   //视频类型
        QMediaModel *model = [modleBuilder build];
        [self.playerContext.controlHandler playMediaModel:model startPos:0];
    

    销毁

       [self.playerContext.controlHandler playerRelease];       
       self.playerContext = nil;
    

    方法二:

    初始化

        NSString *documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];  
        self.playerContext =  [[QPlayerView alloc]initWithFrame:CGRectMake(0, 100, 100, 100) APPVersion:@"" localStorageDir:documentsDir logLevel:LOG_VERBOSE];
        [self.view addSubview:self.playerContext];
    

    播放

        //参数为该视频师傅是直播,YES为是直播,NO为不是直播
        QMediaModelBuilder *modleBuilder = [[QMediaModelBuilder alloc] initWithIsLive:NO];
        [modleBuilder addStreamElementWithUserType:@""                                                     //预留字段,可以为空
                                 urlType:QURL_TYPE_QAUDIO_AND_VIDEO                      //资源的类型,这里的url对应的资源是音视频
                                 url:@"http://demo-videos.qnsdk.com/qiniu-1080p.mp4"     //播放地址
                                 quality:1080                                            //清晰度数值标记为1080
                                 isSelected:YES                                          //是否是默认元素,默认元素是指,起播的时候默认会播放这个元素
                                 backupUrl:@""                                            //备用地址
                                 referer:@""                                              //http/https 协议的地址 支持该属性              
                                 renderType:QPLAYER_RENDER_TYPE_PLANE];                   //视频类型
        QMediaModel *model = [modleBuilder build];
        [self.playerContext.controlHandler playMediaModel:model startPos:0];
    

    销毁

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