From 4f92e31e23ba0bd3d6c02333e13016e39bbf47cb Mon Sep 17 00:00:00 2001 From: lloyd <754415+llince@user.noreply.gitee.com> Date: Sat, 29 Mar 2025 12:00:00 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=B8=80=E6=AC=A1=E5=BC=80=E5=8F=91?= =?UTF-8?q?=EF=BC=8C=E5=A4=9A=E7=AB=AF=E9=83=A8=E7=BD=B2-=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E4=B8=93=E8=BE=91=E3=80=91=E7=BC=96=E8=AF=91=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 8 ++-- README.md | 8 ++-- .../src/main/ets/utils/BackgroundUtil.ets | 39 ++++++++++--------- common/mediaCommon/src/main/module.json5 | 5 +++ .../src/main/ets/view/ListItemComponent.ets | 2 +- .../ets/components/MusicControlComponent.ets | 4 +- .../musicList/src/main/ets/lyric/LrcView.ets | 2 +- 7 files changed, 39 insertions(+), 29 deletions(-) diff --git a/README.en.md b/README.en.md index e6d391f..56685ea 100644 --- a/README.en.md +++ b/README.en.md @@ -16,10 +16,6 @@ The figure shows the effect on the tablet. ![](screenshots/device/pad.en.png) -### Permissions - -N/A - ### How to Use 1. Install and open an app on a mobile phone, foldable phone, or tablet. The responsive layout and adaptive layout are used to display different effects on the app pages over different devices. @@ -28,6 +24,10 @@ N/A 4. Tap the comment button on the page to go to the corresponding comment page. 5. Other buttons do not have actual tap events or functions. +### Permissions + +N/A + ### Constraints 1. The sample is only supported on Huawei phones with standard systems. diff --git a/README.md b/README.md index c72b577..b6c4b87 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,6 @@ ![](screenshots/device/pad.png) -### 相关权限 - -不涉及 - ### 使用说明 1. 分别在手机、折叠屏、平板安装并打开应用,不同设备的应用页面通过响应式布局和自适应布局呈现不同的效果。 @@ -28,6 +24,10 @@ 4. 点击界面上评论按钮跳转到对应的评论页面。 5. 其他按钮无实际点击事件或功能。 +### 相关权限 + +不涉及 + ### 约束与限制 1. 本示例仅支持标准系统上运行,支持设备:华为手机。 diff --git a/common/mediaCommon/src/main/ets/utils/BackgroundUtil.ets b/common/mediaCommon/src/main/ets/utils/BackgroundUtil.ets index cff7b52..1ac92b3 100644 --- a/common/mediaCommon/src/main/ets/utils/BackgroundUtil.ets +++ b/common/mediaCommon/src/main/ets/utils/BackgroundUtil.ets @@ -19,7 +19,6 @@ import { BusinessError } from '@kit.BasicServicesKit'; import { Logger } from './Logger'; export class BackgroundUtil { - /** * Start background task. * @@ -44,15 +43,17 @@ export class BackgroundUtil { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: Object) => { try { - backgroundTaskManager.startBackgroundRunning(context, - backgroundTaskManager.BackgroundMode.AUDIO_PLAYBACK, wantAgentObj).then(() => { - Logger.info('this avPlayer: ', 'startBackgroundRunning succeeded'); - }).catch((error: BusinessError) => { - Logger.error('this avPlayer: ', `startBackgroundRunning failed Cause: code ${error.code}`); - }); + if (canIUse('SystemCapability.ResourceSchedule.BackgroundTaskManager.Core')) { + backgroundTaskManager.startBackgroundRunning(context, + backgroundTaskManager.BackgroundMode.AUDIO_PLAYBACK, wantAgentObj).then(() => { + Logger.info('this avPlayer: ', 'startBackgroundRunning succeeded'); + }).catch((error: BusinessError) => { + Logger.error('this avPlayer: ', `startBackgroundRunning failed Cause: code ${error.code}`); + }); + } } catch (error) { - Logger.error('this avPlayer: ', `startBackgroundRunning failed. code ${(error as BusinessError).code} - message ${(error as BusinessError).message}`); + Logger.error('this avPlayer: ', + `startBackgroundRunning failed. code ${(error as BusinessError).code} message ${(error as BusinessError).message}`); } }); } @@ -63,15 +64,17 @@ export class BackgroundUtil { * @param context */ public static stopContinuousTask(context: common.UIAbilityContext): void { - try { - backgroundTaskManager.stopBackgroundRunning(context).then(() => { - Logger.info('this avPlayer: ', 'stopBackgroundRunning succeeded'); - }).catch((error: BusinessError) => { - Logger.error('this avPlayer: ', `stopBackgroundRunning failed Cause: code ${error.code}`); - }); - } catch (error) { - Logger.error('this avPlayer: ', `stopBackgroundRunning failed. code ${(error as BusinessError).code} - message ${(error as BusinessError).message}`); + if (canIUse('SystemCapability.ResourceSchedule.BackgroundTaskManager.Core')) { + try { + backgroundTaskManager.stopBackgroundRunning(context).then(() => { + Logger.info('this avPlayer: ', 'stopBackgroundRunning succeeded'); + }).catch((error: BusinessError) => { + Logger.error('this avPlayer: ', `stopBackgroundRunning failed Cause: code ${error.code}`); + }); + } catch (error) { + Logger.error('this avPlayer: ', + `stopBackgroundRunning failed. code ${(error as BusinessError).code} message ${(error as BusinessError).message}`); + } } } } \ No newline at end of file diff --git a/common/mediaCommon/src/main/module.json5 b/common/mediaCommon/src/main/module.json5 index fe39b67..9a0b309 100644 --- a/common/mediaCommon/src/main/module.json5 +++ b/common/mediaCommon/src/main/module.json5 @@ -6,6 +6,11 @@ "phone", "tablet", "2in1" + ], + "requestPermissions": [ + { + "name": "ohos.permission.KEEP_BACKGROUND_RUNNING" + } ] } } diff --git a/features/musicComment/src/main/ets/view/ListItemComponent.ets b/features/musicComment/src/main/ets/view/ListItemComponent.ets index 1bccba5..5bfc207 100644 --- a/features/musicComment/src/main/ets/view/ListItemComponent.ets +++ b/features/musicComment/src/main/ets/view/ListItemComponent.ets @@ -19,7 +19,7 @@ import { CommonConstants } from '../constants/CommonConstants'; @Component export struct ListItemComponent { - private item: Comment = new Comment('', '', '', $r('app.media.ic_avatar12')); + public item: Comment = new Comment('', '', '', $r('app.media.ic_avatar12')); build() { Row() { diff --git a/features/musicList/src/main/ets/components/MusicControlComponent.ets b/features/musicList/src/main/ets/components/MusicControlComponent.ets index 1422d6a..e68a0ef 100644 --- a/features/musicList/src/main/ets/components/MusicControlComponent.ets +++ b/features/musicList/src/main/ets/components/MusicControlComponent.ets @@ -110,6 +110,7 @@ export struct MusicControlComponent { left: $r('app.float.margin_small'), right: $r('app.float.margin_small') }) + GridCol({ span: { md: BreakpointConstants.SPAN_SM } }) { @@ -157,6 +158,7 @@ export struct MusicControlComponent { bottom: $r('app.float.common_margin') }) } + GridCol({ span: { md: BreakpointConstants.SPAN_SM, lg: BreakpointConstants.SPAN_MD }, offset: { lg: BreakpointConstants.OFFSET_MD } @@ -242,7 +244,7 @@ export struct MusicControlComponent { */ getImageColor() { if (!this.context) { - return ; + return; } this.context.resourceManager.getMediaContent(this.songList[this.selectIndex].label) .then((value: Uint8Array) => { diff --git a/features/musicList/src/main/ets/lyric/LrcView.ets b/features/musicList/src/main/ets/lyric/LrcView.ets index 01063ca..84e8552 100644 --- a/features/musicList/src/main/ets/lyric/LrcView.ets +++ b/features/musicList/src/main/ets/lyric/LrcView.ets @@ -75,7 +75,7 @@ export default struct shiLrcView { /** * Location of the lyrics. */ - private readonly lyricTopPosition: LyricTopPosition = LyricTopPosition.Top; + public readonly lyricTopPosition: LyricTopPosition = LyricTopPosition.Top; /** * Initial position of the first line of the lyrics. -- Gitee