王士厅

音频dialog开发抽取工具类

... ... @@ -64,3 +64,5 @@ export { FirstTabTopSearchComponent } from "./src/main/ets/components/search/Fir
export { ListHasNoMoreDataUI } from "./src/main/ets/components/reusable/ListHasNoMoreDataUI"
export { LottieView } from './src/main/ets/lottie/LottieView'
export { AudioSuspensionModel } from "./src/main/ets/viewmodel/AudioSuspensionModel"
... ...
import { WDPlayerController } from 'wdPlayer';
import { WDPlayerController, PlayerConstants } from 'wdPlayer';
import { PaperReaderSimpleDialog } from './PaperReaderDialog';
import { Logger } from 'wdKit/Index';
import { AudioSuspensionModel } from '../viewmodel/AudioSuspensionModel';
const TAG = 'AudioDialog';
@Preview
@CustomDialog
export struct AudioDialog {
@Consume audioTitle: string;
@Consume currentTime: string;
@Consume totalTime: string;
@Consume progressVal: number;
@State currentStatus: number = 0;
controllerDetail?: CustomDialogController
private playerController: WDPlayerController = new WDPlayerController();
private simpleAudioDialog: CustomDialogController = new CustomDialogController({
builder: PaperReaderSimpleDialog({
... ... @@ -21,8 +29,12 @@ export struct AudioDialog {
})
private AudioSuspension = new AudioSuspensionModel(this.simpleAudioDialog)
onCancel() {
Logger.info(TAG, "cj2024 onCancel = ")
this.AudioSuspension.setPlayerUrl()
}
/**
... ... @@ -38,34 +50,92 @@ export struct AudioDialog {
}
build() {
Stack({ alignContent: Alignment.End }) {
Column() { //标题 时间 进度条
Marquee({
start: true,
step: 5,
loop: Number.POSITIVE_INFINITY,
fromStart: true,
src: this.audioTitle
})
.width("60%")
.height(20)
.fontColor($r("app.color.color_222222"))
.fontSize(14)
.margin({ top: 10, left: 10 })
.alignSelf(ItemAlign.Start)
.onStart(() => {
console.info('Marquee animation complete onStart')
})
.onBounce(() => {
console.info('Marquee animation complete onBounce')
})
.onFinish(() => {
console.info('Marquee animation complete onFinish')
})
Row() {
Image($r("app.media.icon_audio_pause"))
Text(this.currentTime)
.fontSize($r('app.float.font_size_12'))
.fontColor($r('app.color.color_999999'))
.height("100%")
.alignSelf(ItemAlign.Start)
Text("/" + this.totalTime)
.fontSize($r('app.float.font_size_12'))
.fontColor($r('app.color.color_999999'))
.height("100%")
.alignSelf(ItemAlign.Start)
}
.width("100%")
.height(16)
.margin({ top: 4, left: 10 })
Progress({ value: this.progressVal, total: 100, type: ProgressType.Capsule })
.color($r('app.color.color_ED2800'))
.backgroundColor($r('app.color.white'))
.width("100%")
.height(3)
.margin({ top: 7 })
}
.width("100%")
.height("100%")
.justifyContent(FlexAlign.Start)
Row() {
Image(this.currentStatus != PlayerConstants.STATUS_START ? $r("app.media.icon_audio_pause") : $r("app.media.icon_audio_playing"))
.objectFit(ImageFit.Contain)
.margin(18)
.width(24)
.height(24)
}
.width(60)
.height(60)
.backgroundColor(Color.White)
.margin({ right: 12 })
.onClick(() => {
if (this.simpleAudioDialog) {
this.simpleAudioDialog.close()
this.simpleAudioDialog.open()
if (this.simpleAudioDialog) {
setTimeout(() => {
console.log('PaperReaderSimpleDialog delay 1s');
if (this.simpleAudioDialog != undefined) {
this.simpleAudioDialog.close()
if (this.playerController) {
// this.onConfirm()
this.playerController.switchPlayOrPause()
this.currentStatus = this.playerController.getStatus()
}
if (this.simpleAudioDialog != undefined) {
this.simpleAudioDialog.open()
}
}, 500000);
})
Image($r("app.media.icon_audio_close"))
.objectFit(ImageFit.Contain)
.width(24)
.height(24)
.onClick(() => {
if (this.playerController) {
this.playerController.stop()
}
if (this.controllerDetail) {
this.controllerDetail.close()
}
})
}.width(80)
.height(60)
}
.width("65%")
.height(60)
.backgroundColor(Color.White)
.borderRadius(2)
}
}
\ No newline at end of file
... ...
import { Logger } from 'wdKit';
import { WDPlayerController } from 'wdPlayer';
const TAG = 'AudioSuspensionModel'
/**
* 音频悬浮窗公共方法类
*/
export class AudioSuspensionModel {
public playerController: SubscribedAbstractProperty<WDPlayerController> = AppStorage.link<WDPlayerController>('playerController')
public simpleAudioDialog: CustomDialogController = {} as CustomDialogController
constructor(simpleAudioDialog: CustomDialogController) {
this.simpleAudioDialog = simpleAudioDialog
this.initPlayerController()
}
/**
* 判断音频实例是否已存在,不存在则创建
*/
private initPlayerController() {
if(this.playerController === undefined) {
Logger.info(TAG, 'playerController undefined')
AppStorage.setOrCreate('playerController', new WDPlayerController());
this.playerController = AppStorage.link<WDPlayerController>('playerController')
Logger.info(TAG, 'playerController create success')
} else {
Logger.info(TAG, 'playerController already exit')
}
}
/**
* 配置音频地址
*/
public setPlayerUrl() {
// this.playerController.switchPlayOrPause()
Logger.info(TAG, 'handlePlayer')
}
public delete() {
let res: boolean = AppStorage.delete('PropB');
Logger.info(TAG, `delete: ${res}`)
}
}
\ No newline at end of file
... ...