From a24b21efc203e8a22d7ade74fff35f6d346ae6b1 Mon Sep 17 00:00:00 2001 From: A11Even Date: Fri, 14 Feb 2025 16:41:48 +0800 Subject: [PATCH 1/2] MediaPlayerPlayer.ets Signed-off-by: A11Even --- .../components/plugin/player/MediaPlayerPlayer.ets | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/audioplayers_ohos/ohos/src/main/ets/components/plugin/player/MediaPlayerPlayer.ets b/packages/audioplayers_ohos/ohos/src/main/ets/components/plugin/player/MediaPlayerPlayer.ets index 1f8e6b4..8546f4b 100644 --- a/packages/audioplayers_ohos/ohos/src/main/ets/components/plugin/player/MediaPlayerPlayer.ets +++ b/packages/audioplayers_ohos/ohos/src/main/ets/components/plugin/player/MediaPlayerPlayer.ets @@ -20,6 +20,8 @@ import WrappedPlayer from './WrappedPlayer' import media from '@ohos.multimedia.media'; import { BusinessError } from '@ohos.base'; import { Log } from '@ohos/flutter_ohos'; +import { window } from '@kit.ArkUI' +import common from '@ohos.app.ability.common'; const TAG = "MediaPlayerPlayer" const OPERATE_ERROR: number = 801; @@ -85,9 +87,7 @@ export default class MediaPlayerPlayer implements Player { break; case 'playing': // play成功调用后触发该状态机上报 Log.d(TAG, 'AVPlayer state playing called.'); - if (this.stayAwake) { - this.wrappedPlayer.startContinuousTask(); - } + this.wrappedPlayer.startContinuousTask(); break; case 'paused': // pause成功调用后触发该状态机上报 Log.d(TAG, 'AVPlayer state paused called.'); @@ -188,10 +188,12 @@ export default class MediaPlayerPlayer implements Player { || this.mediaPlayer!.state == 'paused' || this.mediaPlayer!.state == 'completed') } - updateContext(context: AudioContextOhos) { + async updateContext(context: AudioContextOhos) { this.mediaPlayer && this.mediaPlayer!.state == 'initialized' &&context.setAttributesOnPlayer(this.mediaPlayer); - if (context.stayAwake && context.stayAwake != this.stayAwake) { - this.wrappedPlayer.startContinuousTask(); + if (context.stayAwake != this.stayAwake) { + let uiContext = getContext(this) as common.UIAbilityContext + let windowClass:window.Window = await window.getLastWindow(uiContext) + windowClass.setWindowKeepScreenOn(context.stayAwake); } this.stayAwake = context.stayAwake } -- Gitee From c3f8cbdb2d2cb78c18f8f12981700796be9d52c2 Mon Sep 17 00:00:00 2001 From: A11Even Date: Fri, 14 Feb 2025 17:35:10 +0800 Subject: [PATCH 2/2] MediaPlayerPlayer.ets Signed-off-by: A11Even --- .../src/main/ets/components/plugin/player/MediaPlayerPlayer.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/audioplayers_ohos/ohos/src/main/ets/components/plugin/player/MediaPlayerPlayer.ets b/packages/audioplayers_ohos/ohos/src/main/ets/components/plugin/player/MediaPlayerPlayer.ets index 8546f4b..742307d 100644 --- a/packages/audioplayers_ohos/ohos/src/main/ets/components/plugin/player/MediaPlayerPlayer.ets +++ b/packages/audioplayers_ohos/ohos/src/main/ets/components/plugin/player/MediaPlayerPlayer.ets @@ -194,8 +194,8 @@ export default class MediaPlayerPlayer implements Player { let uiContext = getContext(this) as common.UIAbilityContext let windowClass:window.Window = await window.getLastWindow(uiContext) windowClass.setWindowKeepScreenOn(context.stayAwake); + this.stayAwake = context.stayAwake } - this.stayAwake = context.stayAwake } async setSource(source: Source) { -- Gitee