直播云

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

    快速开始

    最近更新时间: 2024-06-11 17:46:54

    快速开始

    基于 qplayer2-core 的播放器使用

    导入头文件

    import { QPlayerContextFactory, QIPlayerContext, QLogLevel,QMediaModel,QSurfaceRenderView} from '@QN/QPlayer2-core/qplayer2-core'
    

    初始化

    @State mPlayerContext : QIPlayerContext = QPlayerContextFactory.createPlayerContext(
        QLogLevel.LOG_INFO,
        (AppStorage.get("context") as Context).filesDir,
        bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT).versionName,
        "")
    
    this.mPlayerContext.init(AppStorage.get('context') as Context , getContext(this) as common.UIAbilityContext)
    

    设置显示视图

    一个 QSurfaceRenderView 对应一个 mPlayerContext , 如果一个 mPlayerContext 对应多个 QSurfaceRenderView 无法保证预期效果

    QSurfaceRenderView({ mQPlayerContext: this.mPlayerContext, mXComponentId: this.mXComponentId })
              .width('100%')
              .height('100%')
    

    播放

    let builder : QMediaModelBuilder = new QMediaModelBuilder()
    builder.addStreamElement("",QPlayerUrlType.QAUDIO_AND_VIDEO,1080,"http://demo-videos.qnsdk.com/qiniu-2023-1080p.mp4",true,"","")
    let model : QMediaModel = builder.build(is_live)
    this.mPlayerContext.get_control_handler().playMediaModel(model)
    

    销毁

    this.mPlayerContext.get_control_handler().release()
    
    以上内容是否对您有帮助?
  • Qvm free helper
    Close