直播云

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

    快速开始

    最近更新时间: 2022-09-27 16:39:51

    快速开始

    基于qplayer2-core的播放器使用

    初始化

    在对应布局文件xml中加入播放器控件

    <com.qiniu.qmedia.ui.QSurfacePlayerView
                android:id="@+id/player_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    </com.qiniu.qmedia.ui.QSurfacePlayerView>
    

    初始化播放器代码建议放在Activity的onCreate中或者是Fragment的onCreate

    mQSurfacePlayerView = findViewById(R.id.player_view)
    mQSurfacePlayerView.playerControlHandler.init(this)
    mQSurfacePlayerView.playerControlHandler.setDecodeType(QPlayerSetting.QPlayerDecoder.QPLAYER_DECODER_SETTING_AUTO)
    mQSurfacePlayerView.playerControlHandler.setDecodeType(QPlayerSetting.QPlayerDecoder.QPLAYER_DECODER_SETTING_AUTO)
    mQSurfacePlayerView.playerControlHandler.setSeekMode(QPlayerSetting.QPlayerSeek.QPLAYER_SEEK_SETTING_NORMAL)
    mQSurfacePlayerView.playerControlHandler.setStartAction(QPlayerSetting.QPlayerStart.QPLAYER_START_SETTING_PLAYING)
    mQSurfacePlayerView.playerControlHandler.setSpeed(1.0)
    

    播放

    builder = QMediaModelBuilder()
    url = "http://demo-videos.qnsdk.com/movies/qiniu.mp4"
    builder.addElement("", QURLType.QAUDIO_AND_VIDEO, 0, url, true)
    var mediaModel = builder.build(false))
    mQSurfacePlayerView.playerControlHandler.playMediaModel(mediaModel, 0)
    

    销毁

    销毁代码建议放在Activity的onDestroy中或者Fragment的onDestroy

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