From 038ed59fd1e459d2e7b125dca63878729aede9fe Mon Sep 17 00:00:00 2001 From: lloyd <353627866@qq.com> Date: Thu, 11 Sep 2025 16:00:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E5=AE=9E=E7=8E=B0=E5=A4=9AHap?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=8A=9F=E8=83=BD=E3=80=91=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- audioFeature/src/main/ets/pages/Index.ets | 67 ++++++++++++----------- entry/src/main/ets/pages/Index.ets | 3 +- hvigor/hvigor-config.json5 | 2 +- oh-package.json5 | 2 +- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/audioFeature/src/main/ets/pages/Index.ets b/audioFeature/src/main/ets/pages/Index.ets index b080e20..6055764 100644 --- a/audioFeature/src/main/ets/pages/Index.ets +++ b/audioFeature/src/main/ets/pages/Index.ets @@ -13,24 +13,24 @@ * limitations under the License. */ -import { media } from '@kit.MediaKit' -import Logger from '../util/Logger' import { common } from '@kit.AbilityKit'; -import { BusinessError } from '@kit.BasicServicesKit' +import { BusinessError } from '@kit.BasicServicesKit'; +import { media } from '@kit.MediaKit'; +import Logger from '../util/Logger'; -const TAG: string = 'Index' -const FD_PREFIX: string = 'fd://' +const TAG: string = 'Index'; +const FD_PREFIX: string = 'fd://'; let player: media.AVPlayer; media.createAVPlayer().then((video: media.AVPlayer) => { if (video != null) { player = video; - console.info('createAVPlayer success'); + Logger.info(TAG, 'createAVPlayer success'); } else { - console.error('createAVPlayer fail'); + Logger.error(TAG, 'createAVPlayer fail'); } }).catch((error: BusinessError) => { - console.error(`AVPlayer catchCallback, error message:${error.message}`); + Logger.error(TAG, `AVPlayer catchCallback, error message:${error.message}`); }); @Entry @@ -42,27 +42,26 @@ struct Index { build() { Row() { - Button({type: ButtonType.Circle, stateEffect: true}) { - Image($r("app.media.play")).width(35).height(35) + Button({ type: ButtonType.Circle, stateEffect: true }) { + Image($r('app.media.play')).width(35).height(35) } - .onClick((event) => { - Logger.info(TAG, "play button clicked, hasInit: " + this.hasInit) - console.log("this.hasInit",this.hasInit) + .onClick(() => { + Logger.info(TAG, 'play button clicked, hasInit: ' + this.hasInit) if (this.hasInit) { - player.play() + player.play(); } else { - this.initAudioPlayer() + this.initAudioPlayer(); } }) .id('btnAudioPlay') .backgroundColor(0xFFFFFF) - .margin({right: 15}) + .margin({ right: 15 }) - Button({type: ButtonType.Circle, stateEffect: true}) { - Image($r("app.media.pause")).width(35).height(35) + Button({ type: ButtonType.Circle, stateEffect: true }) { + Image($r('app.media.pause')).width(35).height(35) } .onClick((event) => { - player.pause() + player.pause(); }) .id('btnAudioStop') .backgroundColor(0xFFFFFF) @@ -73,11 +72,15 @@ struct Index { } initAudioPlayer() { - if(this.context){ - this.setCallback(player) - this.context.resourceManager.getRawFd("1.mp3").then(value => { - player.fdSrc = value - }) + if (this.context) { + this.setCallback(player); + this.context.resourceManager.getRawFd('1.mp3') + .then(value => { + player.fdSrc = value + }) + .catch((error: BusinessError) => { + Logger.error(TAG, `getRawFd failed, error code=${error.code}, message=${error.message}`); + }) } } @@ -85,20 +88,22 @@ struct Index { player.on('stateChange', this.stateChangeCallback = async (state: string, reason: media.StateChangeReason) => { switch (state) { case 'idle': - console.info('state idle called'); + Logger.info(TAG, 'state idle called'); break; case 'initialized': - Logger.info(TAG, 'initialized prepared called') + Logger.info(TAG, 'initialized prepared called'); this.hasInit = true; player.prepare().then(() => { - player.play() + player.play(); + }).catch((error: BusinessError) => { + Logger.error(TAG, `prepare failed, error code=${error.code}, message=${error.message}`); }) break; case 'playing': - Logger.info(TAG, 'audio play success') + Logger.info(TAG, 'audio play success'); break; case 'paused': - Logger.info(TAG, 'audio paused success') + Logger.info(TAG, 'audio paused success'); break; case 'error': Logger.error('state error called'); @@ -107,10 +112,10 @@ struct Index { Logger.info('unkown state :' + state); break; } - }) + }); } aboutToAppear() { - this.context = this.getUIContext().getHostContext() as common.UIAbilityContext + this.context = this.getUIContext().getHostContext() as common.UIAbilityContext; } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index abb3479..916fdf1 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -72,7 +72,6 @@ struct Index { } aboutToAppear() { - this.context = this.getUIContext().getHostContext() as common.UIAbilityContext - + this.context = this.getUIContext().getHostContext() as common.UIAbilityContext; } } \ No newline at end of file diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 index f70ecd4..a2a2e37 100644 --- a/hvigor/hvigor-config.json5 +++ b/hvigor/hvigor-config.json5 @@ -1,5 +1,5 @@ { - "modelVersion": "5.0.0", + "modelVersion": "5.0.5", "dependencies": { } } \ No newline at end of file diff --git a/oh-package.json5 b/oh-package.json5 index 9f50643..0a0df96 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -1,5 +1,5 @@ { - "modelVersion": "5.0.0", + "modelVersion": "5.0.5", "license": "ISC", "devDependencies": { }, -- Gitee From bda885f48ad76231a3d209930530b691958f2ee5 Mon Sep 17 00:00:00 2001 From: lloyd <353627866@qq.com> Date: Thu, 11 Sep 2025 16:02:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90=E5=AE=9E=E7=8E=B0=E5=A4=9AHap?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=8A=9F=E8=83=BD=E3=80=91=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- audioFeature/build-profile.json5 | 3 --- videoFeature/build-profile.json5 | 3 --- 2 files changed, 6 deletions(-) diff --git a/audioFeature/build-profile.json5 b/audioFeature/build-profile.json5 index 5f0c96d..2e52bce 100644 --- a/audioFeature/build-profile.json5 +++ b/audioFeature/build-profile.json5 @@ -17,9 +17,6 @@ "apiType": 'stageMode', "buildOption": { }, - "entryModules": [ - "entry" - ], "targets": [ { "name": "default" diff --git a/videoFeature/build-profile.json5 b/videoFeature/build-profile.json5 index 5f0c96d..2e52bce 100644 --- a/videoFeature/build-profile.json5 +++ b/videoFeature/build-profile.json5 @@ -17,9 +17,6 @@ "apiType": 'stageMode', "buildOption": { }, - "entryModules": [ - "entry" - ], "targets": [ { "name": "default" -- Gitee