From 4af7f394cf64c69db942bc259fdb0b3dfab7ed00 Mon Sep 17 00:00:00 2001 From: wangyu Date: Fri, 20 Mar 2026 09:48:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=9F=B3=E9=A2=91=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/common/RouterUrls.ets | 5 - .../src/main/ets/dialog/AudioPlayerDialog.ets | 8 +- .../main/ets/pages/audio/AudioPlayerPage.ets | 237 ------------------ .../src/main/ets/pages/main/mine/MinePage.ets | 6 +- .../resources/base/profile/main_pages.json | 1 - 5 files changed, 7 insertions(+), 250 deletions(-) delete mode 100644 entry/src/main/ets/pages/audio/AudioPlayerPage.ets diff --git a/entry/src/main/ets/common/RouterUrls.ets b/entry/src/main/ets/common/RouterUrls.ets index 9a2c752..f6f8222 100644 --- a/entry/src/main/ets/common/RouterUrls.ets +++ b/entry/src/main/ets/common/RouterUrls.ets @@ -134,11 +134,6 @@ export class RouterUrls { */ static readonly VIDEO_PLAYER_PAGE = "pages/video/VideoPlayerPage" - /** - * 音频播放页 - */ - static readonly AUDIO_PLAYER_PAGE = "pages/audio/AudioPlayerPage" - /** * 图片查看页 */ diff --git a/entry/src/main/ets/dialog/AudioPlayerDialog.ets b/entry/src/main/ets/dialog/AudioPlayerDialog.ets index afc7db1..5f7661a 100644 --- a/entry/src/main/ets/dialog/AudioPlayerDialog.ets +++ b/entry/src/main/ets/dialog/AudioPlayerDialog.ets @@ -178,7 +178,8 @@ export struct AudioPlayerDialog { Image(this.index > 0 ? $r('app.media.ic_last_audio_enable') : $r('app.media.ic_last_audio_disable')).width(20).height(20) .onClick(async () => { if (this.index > 0) { - await this.avPlayer!!.stop() + await this.avPlayer!!.pause() + await this.avPlayer!!.reset() this.index-- this.uri = this.mediaList[this.index].uri this.title = this.mediaList[this.index].name @@ -189,7 +190,6 @@ export struct AudioPlayerDialog { } } }) - .visibility(Visibility.None) Image(this.isPlaying ? $r('app.media.ic_audio_pause') : $r('app.media.ic_audio_play')).width(30).height(30) .margin({left: 50, right: 50}) @@ -206,7 +206,8 @@ export struct AudioPlayerDialog { .rotate({angle: 180}) .onClick(async () => { if (this.index < this.mediaList.length - 1) { - await this.avPlayer!!.stop() + await this.avPlayer!!.pause() + await this.avPlayer!!.reset() this.index++ this.uri = this.mediaList[this.index].uri this.title = this.mediaList[this.index].name @@ -217,7 +218,6 @@ export struct AudioPlayerDialog { } } }) - .visibility(Visibility.None) } .width('100%') .justifyContent(FlexAlign.Center) diff --git a/entry/src/main/ets/pages/audio/AudioPlayerPage.ets b/entry/src/main/ets/pages/audio/AudioPlayerPage.ets deleted file mode 100644 index 0f502cf..0000000 --- a/entry/src/main/ets/pages/audio/AudioPlayerPage.ets +++ /dev/null @@ -1,237 +0,0 @@ -import { TipDialog } from '../../dialog/TipDialog' -import { ShareManager } from '../../manager/ShareManager' -import { TitleBar } from '../../view/TitleBar' -import { ToastUtils } from '../../utils/ToastUtils' -import { AppUtil } from '@pura/harmony-utils' -import { EventConstants } from '../../common/EventConstants' -import { MediaAction, MediaType } from '../../manager/MediaManager' -import { media } from '@kit.MediaKit' -import { fileIo } from '@kit.CoreFileKit' -import { LocalMediaManager } from '../../manager/LocalMediaManager' -import { avSessionManager } from '../../manager/AVSessionManager' - -@Entry -@ComponentV2 -struct AudioPlayerPage { - @Local title: string = '' - @Local uri: string = '' - @Local showActions: boolean = false - @Local currentTime: number = 0 - @Local durationTime: number = 0 - @Local isPlaying: boolean = false - - avPlayer?: media.AVPlayer; - - aboutToAppear(): void { - this.initParams() - this.initPlayer() - } - - onPageHide(): void { - if (this.avPlayer) { - this.avPlayer.pause() - } - } - - aboutToDisappear(): void { - if (this.avPlayer) { - this.avPlayer.release() - } - } - - initParams() { - const params = this.getUIContext().getRouter().getParams() as Record; - if (params) { - this.title = params.title as string - this.uri = params.uri as string; - this.showActions = params.showActions as boolean - } - } - - async initPlayer() { - this.avPlayer = await media.createAVPlayer(); - // 创建状态机变化回调函数 - this.setAVPlayerCallback(); - // 打开相应的资源文件地址获取fd - let file = await fileIo.open(this.uri); - this.avPlayer.url = 'fd://' + file.fd; - } - - formatTime(time: number): string { - let minute: number = 0 - let second: number = 0 - if (time > 60) { - minute = Math.trunc(time / 60) - second = time % 60 - if (minute < 10) { - if (second < 10) { - return `0${minute}:0${second}` - } else { - return `0${minute}:${second}` - } - } else { - if (second < 10) { - return `${minute}:0${second}` - } else { - return `${minute}:${second}` - } - } - } else { - second = time - if (second < 10) { - return `00:0${second}` - } else { - return `00:${second}` - } - } - } - - // 注册avplayer回调函数 - setAVPlayerCallback() { - this.avPlayer!!.on('error', (err) => { - console.error(`播放器发生错误,错误码:${err.code}, 错误信息:${err.message}`); - // 调用reset重置资源,触发idle状态 - this.isPlaying = false - this.avPlayer!!.reset(); - avSessionManager.deactivate() - }) - // 状态机变化回调函数 - this.avPlayer!!.on('stateChange', async (state, reason) => { - switch (state) { - case 'initialized': - console.info('资源初始化完成'); - // 资源初始化完成,开始准备文件 - this.avPlayer!!.prepare(); - break; - case 'prepared': - console.info('资源准备完成'); - // 资源准备完成,开始准备文件 - this.durationTime = Math.trunc(this.avPlayer!!.duration / 1000) - this.currentTime = this.avPlayer!!.currentTime; - - await avSessionManager.activate() - this.avPlayer!!.play(); - break; - case 'completed': - console.info('播放完成'); - this.isPlaying = false - this.avPlayer!!.off('bufferingUpdate') - AppStorage.setOrCreate('currentTime', this.durationTime); - avSessionManager.deactivate() - break; - case 'playing': - console.info('播放开始'); - this.isPlaying = true - break; - case 'released': - case 'stopped': - case 'error': - case 'paused': - console.info('播放暂停'); - this.isPlaying = false - avSessionManager.deactivate() - break; - } - }) - // 时间上报监听函数 - this.avPlayer!!.on('timeUpdate', (time: number) => { - this.currentTime = Math.trunc(time / 1000); - }); - } - - build() { - Column() { - TitleBar().width('100%') - - RelativeContainer() { - Image($r('app.media.ic_audio_thumb')) - - Row() { - Image(this.isPlaying ? $r('app.media.ic_player_controls_pause') : $r('app.media.ic_player_controls_play')) - .width(20) - .height(20) - .margin({ right: 20 }) - .onClick(async () => { - if (this.isPlaying) { - this.avPlayer!!.pause() - } else { - await avSessionManager.activate() - this.avPlayer!!.play() - } - }) - Text(this.formatTime(this.currentTime)).width(35).fontColor(Color.White).fontSize(12) - Slider({ - value: this.currentTime, - min: 0, - max: this.durationTime - }) - .blockColor(Color.White) - .trackColor($r('app.color.color_60ffffff')) - .onChange((value: number, mode: SliderChangeMode) => { - this.avPlayer!!.seek(value * 1000, 2); // 设置视频播放的进度跳转到value处 - this.currentTime = value; - }) - .layoutWeight(1) - Text(this.formatTime(this.durationTime)).width(35).fontColor(Color.White).fontSize(12) - } - .opacity(0.8) - .width("100%") - .padding({ left: 30, right: 30 }) - .margin({ bottom: this.showActions ? 0 : 50}) - .alignRules({ - bottom: { anchor: '__container__', align: VerticalAlign.Bottom } - }) - }.layoutWeight(1) - - Row() { - Column() { - Image($r('app.media.ic_action_share')).width(50).height(50) - Text('转发').fontSize(12).fontColor($r('app.color.color_50ffffff')).margin({ top: 13 }) - } - .id('btn_share') - .alignRules({ - right: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .margin({ right: 40 }) - .onClick(() => { - ShareManager.shareFile(this.uri) - }) - - Column() { - Image($r('app.media.ic_action_delete')).width(50).height(50) - Text('删除').fontSize(12).fontColor($r('app.color.color_50ffffff')).margin({ top: 13 }) - } - .id('btn_delete') - .alignRules({ - left: { anchor: '__container__', align: HorizontalAlign.Center }, - }) - .margin({ left: 40 }) - .onClick(() => { - this.avPlayer!!.pause() - TipDialog.show(this.getUIContext(), { - title: '提示', content: '确定删除该音频?', callback: { - confirm: () => { - fileIo.unlink(this.uri) - .then(() => { - ToastUtils.show('删除成功') - LocalMediaManager.delete(this.title) - AppUtil.getContext().eventHub.emit(EventConstants.MediaActionEvent, MediaType.AUDIO, MediaAction.DELETE) - this.getUIContext().getRouter().back() - }) - .catch(() => { - ToastUtils.show('删除失败, 请到文件管理中手动删除') - }) - } - } - }) - }) - } - .height(200) - .margin({ top: 10 }) - .visibility(this.showActions ? Visibility.Visible : Visibility.None) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.window_background')) - } -} \ No newline at end of file diff --git a/entry/src/main/ets/pages/main/mine/MinePage.ets b/entry/src/main/ets/pages/main/mine/MinePage.ets index f603e95..53866a6 100644 --- a/entry/src/main/ets/pages/main/mine/MinePage.ets +++ b/entry/src/main/ets/pages/main/mine/MinePage.ets @@ -23,13 +23,12 @@ import { AudioRecordPage } from './record/AudioRecordPage'; @ComponentV2 export struct MinePage { - @Local showChallenge: boolean = false; - @Local showShare: boolean = false; @Local isLogin: boolean = LoginManager.isLogin(); @Local userinfo?: UserEntity; @Local diamondInfo?: DiamondDetailEntity @Local currentIndex: number = 0; @Local tabBarModifier: CommonModifier = new CommonModifier() + @Local menuList: Array = [] private viewModel: MineViewModel = new MineViewModel(this.getUIContext()); @@ -41,6 +40,7 @@ export struct MinePage { @Monitor('viewModel.userEntity') onUserinfoChange(monitor: IMonitor) { this.userinfo = monitor.value()?.now as UserEntity; + this.menuList = mineMenuList().convertToArray() } @Monitor('viewModel.wxService') @@ -287,7 +287,7 @@ export struct MinePage { Text('常用工具').fontColor($r('app.color.color_212226')).fontSize(16).fontWeight(FontWeight.Medium).margin({top: 20}) Grid() { - ForEach(mineMenuList().convertToArray(), (item: MenuEntity) => { + ForEach(this.menuList, (item: MenuEntity) => { GridItem() { Column() { Image(item.icon) diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 994f741..0a53355 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -28,7 +28,6 @@ "pages/main/mine/setting/account/BindAccountPage", "pages/main/mine/setting/account/ManageAccountPage", "pages/video/VideoPlayerPage", - "pages/audio/AudioPlayerPage", "pages/photo/PhotoViewPage" ] }