GlobalSetting.ets 1.42 KB
import { AliPlayerGlobalSettings, AliPlayer } from 'premierlibrary';

import fs from '@ohos.file.fs';
import common from '@ohos.app.ability.common';
import { error } from 'premierlibrary/src/main/ets/com/aliyun/player/IPlayer';
import { BusinessError } from '@kit.BasicServicesKit';

let currentContext = getContext() as common.UIAbilityContext

export function initGlobalPlayerSettings(context?: common.UIAbilityContext) {

  AliPlayerGlobalSettings.setUseHttp2(true);

  let filesDir = (context != undefined ? context : currentContext).filesDir;
  let cachePath = filesDir + "/player-cache"

  fs.stat(cachePath).catch((error: BusinessError) => {
    if (error.code = 13900002) {
      fs.mkdirSync(cachePath)
    }
  })

  AliPlayerGlobalSettings.enableLocalCache(true,1 * 1024, cachePath)

  AliPlayerGlobalSettings.setCacheFileClearConfig(3 * 24 * 6, 1024, 300)
}

export function setupPlayerConfig(player: AliPlayer) {
  let config = player.getConfig()
  if (config) {
    config.mMaxDelayTime = 500
    config.mMaxBufferDuration = 50000
    config.mHighBufferDuration = 3000
    config.mStartBufferDuration = 50
    config.mEnableLowLatencyMode = true
    player.setConfig(config)
  }
}

/*
 * 开启前注意:
 * 1、配置好包名对应的license文件
 * 2、页面组件播放器控制器使用WDAliPlayerController
 * 3、WDAliListPlayerController 暂时由于SDK问题,不能使用
 * 4、
 * */
export const enableAliPlayer = true