GlobalSetting.ets
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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