xugenyuan

ref |> Revert "ref |> 新增阿里播放器SDK封装"

This reverts commit fd4ac238.
... ... @@ -11,7 +11,3 @@ export { PlayerConstants } from "./src/main/ets/constants/PlayerConstants"
export { SpeedBean } from "./src/main/ets/bean/SpeedBean"
export { DateFormatUtil } from "./src/main/ets/utils/DateFormatUtil"
export { WDAliPlayerController } from "./src/main/ets/controller/WDAliPlayerController"
export { WDListPlayerData, WDAliListPlayerController } from "./src/main/ets/controller/WDAliListPlayerController"
\ No newline at end of file
... ...
... ... @@ -7,7 +7,6 @@
"main": "Index.ets",
"version": "1.0.0",
"dependencies": {
"wdKit": "file:../../commons/wdKit",
"premierlibrary": "file:./libs/premierlibrary.har"
"wdKit": "file:../../commons/wdKit"
}
}
... ...
... ... @@ -5,8 +5,6 @@ export class PlayerConstants {
static readonly STATUS_START: number = 1;
static readonly STATUS_PAUSE: number = 2;
static readonly STATUS_STOP: number = 3;
static readonly STATUS_ERROR: number = 4;
static readonly STATUS_COMPLETION: number = 5;
static readonly OPERATE_STATE: Array<string> = ['prepared','playing', 'paused', 'completed'];
... ...
import { AliPlayerFactory, AliPlayer, InfoBean, UrlSource, ErrorInfo, InfoCode } from 'premierlibrary';
import {
idle,
initalized,
prepared,
started,
paused,
stopped,
completion,
error} from 'premierlibrary/src/main/ets/com/aliyun/player/IPlayer';
import { AliListPlayer } from 'premierlibrary/src/main/ets/com/aliyun/player/AliListPlayer'
import { initGlobalPlayerSettings, setupPlayerConfig } from '../utils/GlobalSetting';
import prompt from '@ohos.promptAction';
import { Logger } from '../utils/Logger';
import { PlayerConstants, AVPlayerStatus, Events } from '../constants/PlayerConstants';
export interface WDListPlayerData {
uid: string
url: string
surfaceId?: string
}
/*
* 此播放器为阿里播放器鸿蒙版本封装,可播放单个视频、列表多个视频
* 列表上下滑场景用:WDAliListPlayerController
*
* 阿里文档链接:https://help.aliyun.com/zh/apsara-video-sdk/developer-reference/integrated-hongmeng-harmonyos-next-framework-player-sdk
*/
@Observed
export class WDAliListPlayerController {
private initPromise: Promise<void>;
private avPlayer?: AliListPlayer;
// 内部播放器状态
private avPlayerStatus: number = idle
private duration: number = 0;
private status: number = PlayerConstants.STATUS_IDLE;
private loop: boolean = false;
private url: string = '';
private surfaceId: string = '';
private playSpeed: number = 1;
private seekTime: number = 0;
private positionY: number = 0;
private startTime: number = 0
public errorCode?: number
public errorMesage?: string
public onVideoSizeChange?: (width: number, height: number) => void;
public onBufferUpdate?: (buffered: number, duration: number) => void;
public onTimeUpdate?: (position: number, duration: number) => void;
public onVolumeUpdate?: (volume: number) => void;
// 播放完成,决定是否继续播放回调
public continue?: () => void;
// 准备完成,决定是否播放回调。如果不实现,则自动播放
public onCanplay?: () => void;
public onStatusChange?: (status: number) => void;
public onFirstFrameDisplay?: () => void
//// ------------ 以下为列表播放器属性
private playSources: WDListPlayerData[] = []
private currentPlayRecord?: WDListPlayerData
constructor() {
Logger.info("初始化")
initGlobalPlayerSettings()
this.initPromise = this.createAVPlayer();
}
/**
* 创建 videoPlayer对象
*/
private createAVPlayer(): Promise<void> {
return new Promise((resolve, reject) => {
Logger.debug("开始创建")
let traceId = ''
this.avPlayer = AliPlayerFactory.createAliListPlayer(getContext(), traceId)
if (this.avPlayer) {
Logger.debug("创建完成1")
setupPlayerConfig(this.avPlayer!)
this.bindState();
resolve();
} else {
Logger.error("创建完成0")
Logger.error('[WDPlayerController] createAvPlayer fail!');
reject();
}
});
}
public destory() {
Logger.debug("播放器销毁")
this.avPlayer?.stop()
this.avPlayer?.release()
this.playSources = []
this.currentPlayRecord = undefined
}
/**
* AliPlayer 绑定事件.
*/
private bindState() {
this.avPlayer?.setOnPreparedListener({
// 当调用play()方法后,会调用
onPrepared: () => {
this.duration = this.avPlayer?.getDuration();
Logger.debug("已准备好", `${this.duration}`)
}
}
);
this.avPlayer?.setOnRenderingStartListener({
onRenderingStart: () => {
Logger.debug("首帧开始显示")
if (this.onFirstFrameDisplay) {
this.onFirstFrameDisplay()
}
}
});
this.avPlayer?.setOnCompletionListener({
onCompletion: () => {
Logger.debug("播放完成")
}
});
this.avPlayer?.setOnInfoListener({
onInfo: (bean: InfoBean) => {
if (bean.getCode() === InfoCode.CurrentPosition) {
let position : number = bean.getExtraValue()
Logger.debug(`播放进度条:${position}/ ${this.duration}`)
this.initProgress(position);
} else if (bean.getCode() === InfoCode.BufferedPosition) {
let buffer : number = bean.getExtraValue()
if (this.onBufferUpdate) {
this.onBufferUpdate(buffer, this.duration)
}
} else if (bean.getCode() === InfoCode.SwitchToSoftwareVideoDecoder) {
Logger.debug(`DOWNGRADE TO SOFTWARE DECODE`)
// this.mSwitchedToSoftListener?.onSwitched();
}
}
});
this.avPlayer?.setOnStateChangedListener({
onStateChanged: (status: number) => {
this.avPlayerStatus = status
Logger.debug("status update:" + `${this.getStatusStringWith(status)}`)
switch (status) {
case initalized: {
//this.avPlayer?.prepare();
} break
case prepared: {
if (this.startTime) {
this.setSeekTime(this.startTime, SliderChangeMode.Begin);
}
this.duration = this.avPlayer?.getDuration();
if (this.onVideoSizeChange) {
this.onVideoSizeChange(this.avPlayer?.getVideoWidth(), this.avPlayer?.getVideoHeight());
}
if (this.onCanplay) {
this.onCanplay()
} else {
this.play()
}
} break
case started: {
this.setBright();
this.status = PlayerConstants.STATUS_START;
this.watchStatus();
} break
case paused: {
this.status = PlayerConstants.STATUS_PAUSE;
this.watchStatus();
} break
case stopped: {
this.status = PlayerConstants.STATUS_STOP;
this.watchStatus();
} break
case completion: {
this.status = PlayerConstants.STATUS_COMPLETION;
this.watchStatus();
if (this.continue) {
this.continue();
} else {
//TODO:
//this.duration = 0;
//this.url = this.avPlayer.url || '';
//this.avPlayer.reset();
}
} break
case error: {
// 这里拿不到错误信息
// this.status = PlayerConstants.STATUS_ERROR;
// this.watchStatus();
}
}
}
});
this.avPlayer?.setOnErrorListener({
onError:(errorInfo) => {
Logger.error("播放错误", JSON.stringify(errorInfo))
this.errorCode = errorInfo.getCode()
this.errorMesage = errorInfo.getMsg()
this.status = PlayerConstants.STATUS_ERROR;
this.watchStatus();
}
});
this.avPlayer?.setOnLoadingStatusListener({
onLoadingBegin: () => {
// Logger.error("开始加载。。。")
},
onLoadingProgress: (percent: number, netSpeed: number) => {
// this.loadingProgress = percent;
// this.loadingSpeed = netSpeed;
},
onLoadingEnd: () => {
// Logger.error("结束加载")
// this.showLoadingScene = false;
// this.loadingProgress = 0;
// this.loadingSpeed = 0;
}
});
this.avPlayer?.setOnSeekCompleteListener({
onSeekComplete: () => {
this.initProgress(this.avPlayer?.getCurrentPosition());
}
})
}
private getStatusStringWith(status: number) : string {
switch (status) {
case idle: return 'idle'
case initalized: return 'initalized'
case prepared: return 'prepared'
case started: return 'started'
case paused: return 'paused'
case stopped: return 'stopped'
case completion: return 'completion'
case error: return 'error'
}
return 'unknow'
}
public setXComponentController(controller: XComponentController) {
this.setSurfaceId(controller.getXComponentSurfaceId())
}
public setSurfaceId(surfaceId: string) {
this.surfaceId = surfaceId
}
public async addSources(sources: WDListPlayerData[]) {
if (this.avPlayer == null) {
Logger.info("等待播放器初始化")
await this.initPromise;
}
if (this.avPlayer == null) {
return
}
/// 追加数据源
this.playSources.splice(this.playSources.length, 0, ...sources)
sources.map(data => {
this.avPlayer?.addUrl(data.url, data.uid)
})
}
public moveTo(uid: string, surfaceId: string) {
let uidDatas = this.playSources.filter(data => data.uid === uid)
if (uidDatas.length == 0) {
Logger.info("请先addSources()添加数据源url" + uid)
return
}
this.currentPlayRecord = uidDatas[0]
this.avPlayer?.setSurfaceId(surfaceId)
// this.setAliPlayerURL(this.currentPlayRecord.url)
let result = this.avPlayer?.moveTo(uid)
Logger.info("moveTo" + uid + ` result:${result}`)
this.avPlayer?.prepare()
}
private setAliPlayerURL(url: string) {
let urlSource : UrlSource = new UrlSource()
urlSource.setUri(url)
this.avPlayer?.setUrlDataSource(urlSource)
}
private release() {
if (this.avPlayer == null) {
return
}
this.avPlayer.release()
this.avPlayer = undefined
}
public pause() {
Logger.debug("暂停", this.url)
this.avPlayer?.pause();
}
public play() {
Logger.debug("播放", this.url)
this.avPlayer?.start();
}
public stop() {
Logger.debug("停止", this.url)
this.avPlayer?.stop();
}
public setLoop(loop: boolean) {
this.loop = loop;
this.avPlayer?.setLoop(loop);
}
public setMute(mute: boolean) {
this.avPlayer?.setMute(mute)
}
public setSpeed(playSpeed: number) {
this.playSpeed = playSpeed;
this.avPlayer?.setSpeed(this.playSpeed);
}
public switchPlayOrPause() {
if (this.avPlayerStatus == started) {
this.avPlayer?.pause();
} else if (this.avPlayerStatus == completion) {
this.avPlayer?.seekTo(0, 0)
this.avPlayer?.start()
} else {
this.avPlayer?.start();
}
}
public setSeekTime(value: number, mode: SliderChangeMode) {
// if (this.avPlayer == null) {
// await this.initPromise;
// }
// if (this.avPlayer == null) {
// return
// }
// if (mode == SliderChangeMode.Begin) {
// this.seekTime = value * 1000;
// this.avPlayer?.seek(this.seekTime, media.SeekMode.SEEK_PREV_SYNC);
// }
if (mode === SliderChangeMode.Moving) {
// this.progressThis.progressVal = value;
// this.progressThis.currentTime = DateFormatUtil.secondToTime(Math.floor(value * this.duration /
// 100 / 1000));
}
if (mode === SliderChangeMode.End) {
this.seekTime = Math.floor(value * this.duration / 100);
this.avPlayer?.seekTo(this.seekTime, 0);
}
}
public setBright() {
// globalThis.windowClass.setWindowBrightness(this.playerThis.bright)
}
public getStatus() {
return this.status;
}
public getPlayer() {
return this.avPlayer != undefined
}
initProgress(time: number) {
if (this.onTimeUpdate) {
this.onTimeUpdate(time, this.duration);
}
}
resetProgress() {
this.seekTime = 0;
this.duration = 0;
}
onVolumeActionStart(event: GestureEvent) {
this.positionY = event.offsetY;
}
onBrightActionStart(event: GestureEvent) {
this.positionY = event.offsetY;
}
volume: number = 1
onVolumeActionUpdate(event: GestureEvent) {
if (!this.avPlayer) {
return
}
if (this.avPlayerStatus != prepared &&
this.avPlayerStatus != started &&
this.avPlayerStatus != paused &&
this.avPlayerStatus != completion) {
return;
}
let changeVolume = (event.offsetY - this.positionY) / 300;
let currentVolume = this.volume - changeVolume;
if (currentVolume > 1) {
currentVolume = 1;
}
if (currentVolume <= 0) {
currentVolume = 0;
}
this.volume = currentVolume;
this.avPlayer?.setVolume(this.volume);
this.positionY = event.offsetY;
if (this.onVolumeUpdate) {
this.onVolumeUpdate(this.volume);
}
console.log("volume : " + this.volume)
}
onBrightActionUpdate(event: GestureEvent) {
// if (!this.playerThis.volumeShow) {
// this.playerThis.brightShow = true;
// let changeBright = (this.positionY - event.offsetY) / globalThis.screenHeight;
// let currentBright = this.playerThis.bright + changeBright;
// let brightMinFlag = currentBright <= 0;
// let brightMaxFlag = currentBright > 1;
// this.playerThis.bright = brightMinFlag ? 0 :
// (brightMaxFlag ? 1 : currentBright);
// this.setBright();
// this.positionY = event.offsetY;
// }
}
onActionEnd() {
setTimeout(() => {
this.positionY = 0;
}, 200);
}
watchStatus() {
console.log('watchStatus', this.status)
if (this.onStatusChange) {
this.onStatusChange(this.status)
}
// if (this.status === PlayConstants.STATUS_START) {
// globalThis.windowClass.setWindowKeepScreenOn(true);
// } else {
// globalThis.windowClass.setWindowKeepScreenOn(false);
// }
}
playError(msg?: string) {
prompt.showToast({
duration: 3000,
message: msg ? msg : "请检查地址输入正确且网络正常"
});
}
setStartTime(time?: number) {
this.startTime = time ?? 0;
}
}
\ No newline at end of file
import { AliPlayerFactory, AliPlayer, InfoBean, UrlSource, ErrorInfo, InfoCode } from 'premierlibrary';
import {
idle,
initalized,
prepared,
started,
paused,
stopped,
completion,
error} from 'premierlibrary/src/main/ets/com/aliyun/player/IPlayer';
import { initGlobalPlayerSettings, setupPlayerConfig } from '../utils/GlobalSetting';
import prompt from '@ohos.promptAction';
import { Logger } from '../utils/Logger';
import { PlayerConstants, AVPlayerStatus, Events } from '../constants/PlayerConstants';
/*
* 此播放器为阿里播放器鸿蒙版本封装,可播放单个视频、或直播
* 列表上下滑场景用:WDListPlayerController
*
* 阿里文档链接:https://help.aliyun.com/zh/apsara-video-sdk/developer-reference/integrated-hongmeng-harmonyos-next-framework-player-sdk
*/
@Observed
export class WDAliPlayerController {
private initPromise: Promise<void>;
private avPlayer?: AliPlayer;
// 内部播放器状态
private avPlayerStatus: number = idle
private duration: number = 0;
private status: number = PlayerConstants.STATUS_IDLE;
private loop: boolean = false;
private url: string = '';
private surfaceId: string = '';
private playSpeed: number = 1;
private seekTime: number = 0;
private positionY: number = 0;
private startTime: number = 0
public errorCode?: number
public errorMesage?: string
public onVideoSizeChange?: (width: number, height: number) => void;
public onBufferUpdate?: (buffered: number, duration: number) => void;
public onTimeUpdate?: (position: number, duration: number) => void;
public onVolumeUpdate?: (volume: number) => void;
// 播放完成,决定是否继续播放回调
public continue?: () => void;
// 准备完成,决定是否播放回调。如果不实现,则自动播放
public onCanplay?: () => void;
public onStatusChange?: (status: number) => void;
public onFirstFrameDisplay?: () => void
constructor() {
Logger.info("初始化")
initGlobalPlayerSettings()
this.initPromise = this.createAVPlayer();
}
/**
* 创建 videoPlayer对象
*/
private createAVPlayer(): Promise<void> {
return new Promise((resolve, reject) => {
Logger.debug("开始创建")
let traceId = ''
this.avPlayer = AliPlayerFactory.createAliPlayer(getContext(), traceId)
if (this.avPlayer) {
Logger.debug("创建完成1")
setupPlayerConfig(this.avPlayer!)
this.bindState();
resolve();
} else {
Logger.error("创建完成0")
Logger.error('[WDPlayerController] createAvPlayer fail!');
reject();
}
});
}
public destory() {
Logger.debug("播放器销毁")
this.avPlayer?.stop()
this.avPlayer?.release()
}
/**
* AliPlayer 绑定事件.
*/
private bindState() {
this.avPlayer?.setOnPreparedListener({
// 当调用play()方法后,会调用
onPrepared: () => {
this.duration = this.avPlayer?.getDuration();
Logger.debug("已准备好", `${this.duration}`)
}
}
);
this.avPlayer?.setOnRenderingStartListener({
onRenderingStart: () => {
Logger.debug("首帧开始显示")
if (this.onFirstFrameDisplay) {
this.onFirstFrameDisplay()
}
}
});
this.avPlayer?.setOnCompletionListener({
onCompletion: () => {
Logger.debug("播放完成")
}
});
this.avPlayer?.setOnInfoListener({
onInfo: (bean: InfoBean) => {
if (bean.getCode() === InfoCode.CurrentPosition) {
let position : number = bean.getExtraValue()
Logger.debug(`播放进度条:${position}/ ${this.duration}`)
this.initProgress(position);
} else if (bean.getCode() === InfoCode.BufferedPosition) {
let buffer : number = bean.getExtraValue()
if (this.onBufferUpdate) {
this.onBufferUpdate(buffer, this.duration)
}
} else if (bean.getCode() === InfoCode.SwitchToSoftwareVideoDecoder) {
Logger.debug(`DOWNGRADE TO SOFTWARE DECODE`)
// this.mSwitchedToSoftListener?.onSwitched();
}
}
});
this.avPlayer?.setOnStateChangedListener({
onStateChanged: (status: number) => {
this.avPlayerStatus = status
Logger.debug("status update:" + `${this.getStatusStringWith(status)}`)
switch (status) {
case initalized: {
//this.avPlayer?.prepare();
} break
case prepared: {
if (this.startTime) {
this.setSeekTime(this.startTime, SliderChangeMode.Begin);
}
this.duration = this.avPlayer?.getDuration();
if (this.onVideoSizeChange) {
this.onVideoSizeChange(this.avPlayer?.getVideoWidth(), this.avPlayer?.getVideoHeight());
}
if (this.onCanplay) {
this.onCanplay()
} else {
this.play()
}
} break
case started: {
this.setBright();
this.status = PlayerConstants.STATUS_START;
this.watchStatus();
} break
case paused: {
this.status = PlayerConstants.STATUS_PAUSE;
this.watchStatus();
} break
case stopped: {
this.status = PlayerConstants.STATUS_STOP;
this.watchStatus();
} break
case completion: {
this.status = PlayerConstants.STATUS_COMPLETION;
this.watchStatus();
if (this.continue) {
this.continue();
} else {
//TODO:
//this.duration = 0;
//this.url = this.avPlayer.url || '';
//this.avPlayer.reset();
}
} break
case error: {
// 这里拿不到错误信息
// this.status = PlayerConstants.STATUS_ERROR;
// this.watchStatus();
}
}
}
});
this.avPlayer?.setOnErrorListener({
onError:(errorInfo) => {
Logger.error("播放错误", JSON.stringify(errorInfo))
this.errorCode = errorInfo.getCode()
this.errorMesage = errorInfo.getMsg()
this.status = PlayerConstants.STATUS_ERROR;
this.watchStatus();
}
});
this.avPlayer?.setOnLoadingStatusListener({
onLoadingBegin: () => {
// Logger.error("开始加载。。。")
},
onLoadingProgress: (percent: number, netSpeed: number) => {
// this.loadingProgress = percent;
// this.loadingSpeed = netSpeed;
},
onLoadingEnd: () => {
// Logger.error("结束加载")
// this.showLoadingScene = false;
// this.loadingProgress = 0;
// this.loadingSpeed = 0;
}
});
this.avPlayer?.setOnSeekCompleteListener({
onSeekComplete: () => {
this.initProgress(this.avPlayer?.getCurrentPosition());
}
})
}
private setAliPlayerURL(url: string) {
let urlSource : UrlSource = new UrlSource()
urlSource.setUri(url)
this.avPlayer?.setUrlDataSource(urlSource)
}
private getStatusStringWith(status: number) : string {
switch (status) {
case idle: return 'idle'
case initalized: return 'initalized'
case prepared: return 'prepared'
case started: return 'started'
case paused: return 'paused'
case stopped: return 'stopped'
case completion: return 'completion'
case error: return 'error'
}
return 'unknow'
}
setXComponentController(controller: XComponentController) {
this.setSurfaceId(controller.getXComponentSurfaceId())
}
setSurfaceId(surfaceId: string) {
this.surfaceId = surfaceId
}
async firstPlay(url: string) {
this.url = url;
if (this.avPlayer == null) {
Logger.info("等待播放器初始化")
await this.initPromise;
} else {
if (this.avPlayerStatus != idle) {
this.destory()
this.initPromise = this.createAVPlayer();
await this.initPromise;
}
}
if (this.avPlayer == null) {
return
}
this.duration = 0
this.errorCode = undefined
this.errorMesage = undefined
this.avPlayerStatus = idle
this.status = PlayerConstants.STATUS_IDLE
this.avPlayer?.setAutoPlay(false)
Logger.debug("开始播放", this.url)
this.setAliPlayerURL(this.url);
Logger.info("设置SurfaceId" + this.surfaceId)
this.avPlayer?.setSurfaceId(this.surfaceId)
this.avPlayer?.prepare()
}
release() {
if (this.avPlayer == null) {
return
}
this.avPlayer.release()
this.avPlayer = undefined
}
pause() {
Logger.debug("暂停", this.url)
this.avPlayer?.pause();
}
play() {
Logger.debug("播放", this.url)
this.avPlayer?.start();
}
stop() {
Logger.debug("停止", this.url)
this.avPlayer?.stop();
}
setLoop(loop: boolean) {
this.loop = loop;
this.avPlayer?.setLoop(loop);
}
setMute(mute: boolean) {
this.avPlayer?.setMute(mute)
}
setSpeed(playSpeed: number) {
this.playSpeed = playSpeed;
this.avPlayer?.setSpeed(this.playSpeed);
}
switchPlayOrPause() {
if (this.avPlayerStatus == started) {
this.avPlayer?.pause();
} else if (this.avPlayerStatus == completion) {
this.avPlayer?.seekTo(0, 0)
this.avPlayer?.start()
} else {
this.avPlayer?.start();
}
}
setSeekTime(value: number, mode: SliderChangeMode) {
// if (this.avPlayer == null) {
// await this.initPromise;
// }
// if (this.avPlayer == null) {
// return
// }
// if (mode == SliderChangeMode.Begin) {
// this.seekTime = value * 1000;
// this.avPlayer?.seek(this.seekTime, media.SeekMode.SEEK_PREV_SYNC);
// }
if (mode === SliderChangeMode.Moving) {
// this.progressThis.progressVal = value;
// this.progressThis.currentTime = DateFormatUtil.secondToTime(Math.floor(value * this.duration /
// 100 / 1000));
}
if (mode === SliderChangeMode.End) {
this.seekTime = Math.floor(value * this.duration / 100);
this.avPlayer?.seekTo(this.seekTime, 0);
}
}
setBright() {
// globalThis.windowClass.setWindowBrightness(this.playerThis.bright)
}
getStatus() {
return this.status;
}
getPlayer() {
return this.avPlayer != undefined
}
initProgress(time: number) {
if (this.onTimeUpdate) {
this.onTimeUpdate(time, this.duration);
}
}
resetProgress() {
this.seekTime = 0;
this.duration = 0;
}
onVolumeActionStart(event: GestureEvent) {
this.positionY = event.offsetY;
}
onBrightActionStart(event: GestureEvent) {
this.positionY = event.offsetY;
}
volume: number = 1
onVolumeActionUpdate(event: GestureEvent) {
if (!this.avPlayer) {
return
}
if (this.avPlayerStatus != prepared &&
this.avPlayerStatus != started &&
this.avPlayerStatus != paused &&
this.avPlayerStatus != completion) {
return;
}
let changeVolume = (event.offsetY - this.positionY) / 300;
let currentVolume = this.volume - changeVolume;
if (currentVolume > 1) {
currentVolume = 1;
}
if (currentVolume <= 0) {
currentVolume = 0;
}
this.volume = currentVolume;
this.avPlayer?.setVolume(this.volume);
this.positionY = event.offsetY;
if (this.onVolumeUpdate) {
this.onVolumeUpdate(this.volume);
}
console.log("volume : " + this.volume)
}
onBrightActionUpdate(event: GestureEvent) {
// if (!this.playerThis.volumeShow) {
// this.playerThis.brightShow = true;
// let changeBright = (this.positionY - event.offsetY) / globalThis.screenHeight;
// let currentBright = this.playerThis.bright + changeBright;
// let brightMinFlag = currentBright <= 0;
// let brightMaxFlag = currentBright > 1;
// this.playerThis.bright = brightMinFlag ? 0 :
// (brightMaxFlag ? 1 : currentBright);
// this.setBright();
// this.positionY = event.offsetY;
// }
}
onActionEnd() {
setTimeout(() => {
this.positionY = 0;
}, 200);
}
watchStatus() {
console.log('watchStatus', this.status)
if (this.onStatusChange) {
this.onStatusChange(this.status)
}
// if (this.status === PlayConstants.STATUS_START) {
// globalThis.windowClass.setWindowKeepScreenOn(true);
// } else {
// globalThis.windowClass.setWindowKeepScreenOn(false);
// }
}
playError(msg?: string) {
prompt.showToast({
duration: 3000,
message: msg ? msg : "请检查地址输入正确且网络正常"
});
}
setStartTime(time?: number) {
this.startTime = time ?? 0;
}
}
\ No newline at end of file
... ... @@ -134,10 +134,6 @@ export class WDPlayerController {
this.surfaceId = controller.getXComponentSurfaceId()
}
setSurfaceId(surfaceId: string) {
this.surfaceId = surfaceId
}
async firstPlay(url: string) {
this.url = url;
if (this.avPlayer == null) {
... ...
... ... @@ -2,7 +2,6 @@ import componentUtils from '@ohos.arkui.componentUtils';
import { WDPlayerController } from '../controller/WDPlayerController'
import { WindowModel } from 'wdKit';
import { Logger } from '../utils/Logger';
import { enableAliPlayer } from '../utils/GlobalSetting';
class Size {
width: Length = "100%";
... ... @@ -75,9 +74,8 @@ export struct WDPlayerRenderLiveView {
Row() {
// 设置为“surface“类型时XComponent组件可以和其他组件一起进行布局和渲染。
XComponent({
id: enableAliPlayer ? this.insId : 'xComponentId',
type: XComponentType.SURFACE,
libraryname: enableAliPlayer ? "premierlibrary" : undefined,
id: 'xComponentId',
type: 'surface',
controller: this.xComponentController
})
.onLoad(async (event) => {
... ... @@ -89,11 +87,7 @@ export struct WDPlayerRenderLiveView {
surfaceWidth: 1920,
surfaceHeight: 720
});
if (enableAliPlayer) {
this.playerController?.setSurfaceId(this.insId)
} else {
this.playerController?.setXComponentController(this.xComponentController)
}
this.playerController?.setXComponentController(this.xComponentController)
if (this.onLoad) {
this.onLoad(event)
}
... ...
... ... @@ -2,7 +2,6 @@ import componentUtils from '@ohos.arkui.componentUtils';
import { WDPlayerController } from '../controller/WDPlayerController'
import { WindowModel } from 'wdKit';
import { Logger } from '../utils/Logger';
import { enableAliPlayer } from '../utils/GlobalSetting';
class Size {
width: Length = "100%";
... ... @@ -74,9 +73,8 @@ export struct WDPlayerRenderVLiveView {
Row() {
// 设置为“surface“类型时XComponent组件可以和其他组件一起进行布局和渲染。
XComponent({
id: enableAliPlayer ? this.insId : 'xComponentId',
type: XComponentType.SURFACE,
libraryname: enableAliPlayer ? "premierlibrary" : undefined,
id: 'xComponentId',
type: 'surface',
controller: this.xComponentController
})
.onLoad(async (event) => {
... ... @@ -86,11 +84,7 @@ export struct WDPlayerRenderVLiveView {
surfaceWidth: 1920,
surfaceHeight: 1080
});
if (enableAliPlayer) {
this.playerController?.setSurfaceId(this.insId)
} else {
this.playerController?.setXComponentController(this.xComponentController)
}
this.playerController?.setXComponentController(this.xComponentController)
if (this.onLoad) {
this.onLoad(event)
}
... ...
... ... @@ -2,7 +2,6 @@ import componentUtils from '@ohos.arkui.componentUtils';
import { WDPlayerController } from '../controller/WDPlayerController'
import { WindowModel } from 'wdKit';
import { Logger } from '../utils/Logger';
import { enableAliPlayer } from '../utils/GlobalSetting';
class Size {
width: Length = "100%";
... ... @@ -76,7 +75,6 @@ export struct WDPlayerRenderView {
XComponent({
id: this.insId,
type: XComponentType.SURFACE,
libraryname: enableAliPlayer ? "premierlibrary" : undefined,
controller: this.xComponentController
})
.onLoad(async (event) => {
... ... @@ -85,11 +83,7 @@ export struct WDPlayerRenderView {
surfaceWidth: 1920,
surfaceHeight: 1080
});
if (enableAliPlayer) {
this.playerController?.setSurfaceId(this.insId)
} else {
this.playerController?.setXComponentController(this.xComponentController)
}
this.playerController?.setXComponentController(this.xComponentController)
if (this.onLoad) {
this.onLoad(event)
}
... ...
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
player.setConfig(config)
}
}
/*
* 开启前注意:
* 1、配置好包名对应的license文件
* 2、页面组件播放器控制器使用WDAliPlayerController
* 3、WDAliListPlayerController 暂时由于SDK问题,不能使用
* 4、
* */
export const enableAliPlayer = false
\ No newline at end of file
... ... @@ -9,23 +9,6 @@
"2in1"
],
"deliveryWithInstall": true,
"pages": "$profile:main_pages",
"metadata": [
{
"name": "com.aliyun.alivc_license.licensekey",
// "value": "MoCTfuQ391Z01mNqG8f8786e23c8a457a8ff8d5faedc1040c"
"value": "KoETnmCmxJ1e1ZXDj0eb2ddb6c81c4cb7b9912df65e6d8eb2"
},
{
"name": "com.aliyun.alivc_license.licensefile",
// "value": "license.crt"
"value": "pre-license.crt"
},
{
"name": "com.aliyun.alivc_license.service_env",
"value": "PreRelease"
}
]
"pages": "$profile:main_pages"
}
}
\ No newline at end of file
... ...
-----BEGIN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