王士厅

fix: 早晚报语音播放时,进入稿件详情,对稿件中的视频播放,语音没有暂停

@@ -20,23 +20,23 @@ @@ -20,23 +20,23 @@
20 "name": "default", 20 "name": "default",
21 "type": "HarmonyOS", 21 "type": "HarmonyOS",
22 "material": { 22 "material": {
23 - "certpath": "./singing_config/manual_com.peopledailychina.hosactivity_sign/鸿蒙中文版客户端证书.cer",  
24 - "storePassword": "0000001E857CAD6D7E7172B6C87426344CEF8CC3281AB0461B4FA467DA64A1E11BD35929D150343E5D8E1EEE2740",  
25 - "keyAlias": "peopledailyhosalias",  
26 - "keyPassword": "0000001E383EA87F51D8B158D5D1FC9ACC10179A0C93E81FD01B2E24D5B449EF1E50789BCEBC4FA09E3E5445C12A",  
27 - "profile": "./singing_config/manual_com.peopledailychina.hosactivity_sign/peopledaiychina-hos-profile-debugDebug.p7b", 23 + "certpath": "C:\\Users\\Thurman\\.ohos\\config\\default_sight_harmony_QWBSqgX-h8PHbOj8MRnxCwvXCUltlp6P5ebKMKA51TI=.cer",
  24 + "storePassword": "00000019007D1BE372F9267A310C953AEA12FDB4353D441C310E4A4611BFEC577D837C9530B345C64D",
  25 + "keyAlias": "debugKey",
  26 + "keyPassword": "00000019D1436C0369AD6985BD560FAE6620037BB413CBE4E84AE05AD76BC45E637F5FB1E101B70922",
  27 + "profile": "C:\\Users\\Thurman\\.ohos\\config\\default_sight_harmony_QWBSqgX-h8PHbOj8MRnxCwvXCUltlp6P5ebKMKA51TI=.p7b",
28 "signAlg": "SHA256withECDSA", 28 "signAlg": "SHA256withECDSA",
29 - "storeFile": "./singing_config/manual_com.peopledailychina.hosactivity_sign/keystorefile.p12" 29 + "storeFile": "C:\\Users\\Thurman\\.ohos\\config\\default_sight_harmony_QWBSqgX-h8PHbOj8MRnxCwvXCUltlp6P5ebKMKA51TI=.p12"
30 } 30 }
31 }, 31 },
32 { 32 {
33 "name": "release", 33 "name": "release",
34 "type": "HarmonyOS", 34 "type": "HarmonyOS",
35 "material": { 35 "material": {
36 - "storePassword": "0000001E423C7B1ED6AA1EC296F8E9D84C03F7D2E2BD770655E9EABA798E457E15B4D993CCA36416B0200E92DED7",  
37 "certpath": "./singing_config/manual_com.peopledailychina.hosactivity_sign/鸿蒙中文版客户端证书正式.cer", 36 "certpath": "./singing_config/manual_com.peopledailychina.hosactivity_sign/鸿蒙中文版客户端证书正式.cer",
  37 + "storePassword": "0000001E4D643D92F70DFDD813B928597AD5724094204DEB350DE798DBC2FBDAD97C54B58B01CC1B1756F6ED5EDE",
38 "keyAlias": "peopledailyhosalias", 38 "keyAlias": "peopledailyhosalias",
39 - "keyPassword": "0000001E9C2E794B52FC032F4C6ED037D72ADAAC76F3F0F001342A7D79ABE3A45E01FA86911A0510DB2B532847E2", 39 + "keyPassword": "0000001E33EC19E6AB58A6E4968586FEAB93B0990CA5A204048F4630232D6C77A89B5919EC9545ADDA7B4BB56BB4",
40 "profile": "./singing_config/manual_com.peopledailychina.hosactivity_sign/peopledailychina-hos-profile-releaseRelease.p7b", 40 "profile": "./singing_config/manual_com.peopledailychina.hosactivity_sign/peopledailychina-hos-profile-releaseRelease.p7b",
41 "signAlg": "SHA256withECDSA", 41 "signAlg": "SHA256withECDSA",
42 "storeFile": "./singing_config/manual_com.peopledailychina.hosactivity_sign/keystorefile.p12" 42 "storeFile": "./singing_config/manual_com.peopledailychina.hosactivity_sign/keystorefile.p12"
@@ -56,7 +56,9 @@ @@ -56,7 +56,9 @@
56 "BUILD_VERSION": "" 56 "BUILD_VERSION": ""
57 } 57 }
58 }, 58 },
59 - "strictMode": {"useNormalizedOHMUrl": true} 59 + "strictMode": {
  60 + "useNormalizedOHMUrl": true
  61 + }
60 }, 62 },
61 }, 63 },
62 { 64 {
@@ -71,7 +73,9 @@ @@ -71,7 +73,9 @@
71 "BUILD_VERSION": "" 73 "BUILD_VERSION": ""
72 } 74 }
73 }, 75 },
74 - "strictMode": {"useNormalizedOHMUrl": true} 76 + "strictMode": {
  77 + "useNormalizedOHMUrl": true
  78 + }
75 } 79 }
76 } 80 }
77 ], 81 ],
@@ -7,6 +7,8 @@ import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; @@ -7,6 +7,8 @@ import { Message } from 'wdJsBridge/src/main/ets/bean/Message';
7 import { DateTimeUtils,EmitterUtils,EmitterEventId } from 'wdKit' 7 import { DateTimeUtils,EmitterUtils,EmitterEventId } from 'wdKit'
8 import { window } from '@kit.ArkUI'; 8 import { window } from '@kit.ArkUI';
9 import { NativeCallH5Type,NativeCallH5Event,eventParams } from './NativeCallH5Type'; 9 import { NativeCallH5Type,NativeCallH5Event,eventParams } from './NativeCallH5Type';
  10 +import { AudioSuspensionModel } from '../viewmodel/AudioSuspensionModel'
  11 +import { BusinessError } from '@kit.BasicServicesKit';
10 12
11 const TAG = 'WdWebLocalComponent'; 13 const TAG = 'WdWebLocalComponent';
12 14
@@ -44,6 +46,8 @@ export struct WdWebLocalComponent { @@ -44,6 +46,8 @@ export struct WdWebLocalComponent {
44 @Consume @Watch('pageShowForUpdateData') pageShow :number 46 @Consume @Watch('pageShowForUpdateData') pageShow :number
45 @Consume @Watch('pageHideForUpdateData') pageHide :number 47 @Consume @Watch('pageHideForUpdateData') pageHide :number
46 48
  49 + private AudioSuspension = new AudioSuspensionModel()
  50 +
47 currentChanged(){ 51 currentChanged(){
48 ///折叠屏转换 暂停播放器 52 ///折叠屏转换 暂停播放器
49 this.controller.pause() 53 this.controller.pause()
@@ -186,6 +190,19 @@ export struct WdWebLocalComponent { @@ -186,6 +190,19 @@ export struct WdWebLocalComponent {
186 } 190 }
187 } 191 }
188 } 192 }
  193 + // 暂停音频悬浮窗
  194 + pauseAudioCom() {
  195 + // 判断当前窗口是否已显示,使用callback异步回调。
  196 + this.AudioSuspension.floatWindowClass.get().isShowing((err: BusinessError, data) => {
  197 + const errCode: number = err.code;
  198 + if (errCode) {
  199 + return;
  200 + }
  201 + if(data) {
  202 + this.AudioSuspension.playerController.get()?.pause();
  203 + }
  204 + });
  205 + }
189 //播放视频 206 //播放视频
190 private setCurrentPageOperate9: (data: Message) => void = (data) => { 207 private setCurrentPageOperate9: (data: Message) => void = (data) => {
191 if (data.handlerName === H5CallNativeType.jsCall_currentPageOperate && data?.data?.operateType === '9') { 208 if (data.handlerName === H5CallNativeType.jsCall_currentPageOperate && data?.data?.operateType === '9') {
@@ -235,6 +252,7 @@ export struct WdWebLocalComponent { @@ -235,6 +252,7 @@ export struct WdWebLocalComponent {
235 this.cancelProgressTimer() 252 this.cancelProgressTimer()
236 this.controller.start() 253 this.controller.start()
237 this.startProgressTimer() 254 this.startProgressTimer()
  255 + this.pauseAudioCom()
238 } 256 }
239 257
240 startProgressTimer() { 258 startProgressTimer() {
  1 +import window from '@ohos.window';
  2 +import { Logger } from 'wdKit';
  3 +import { BackgroundAudioController, WDPlayerController } from 'wdPlayer';
  4 +import { BusinessError } from '@ohos.base';
  5 +import { EmitterEventId, EmitterUtils } from 'wdKit/Index'
  6 +
  7 +const TAG = 'AudioSuspensionModel'
  8 +
  9 +/**
  10 + * 音频悬浮窗公共方法类
  11 + */
  12 +export class AudioSuspensionModel {
  13 + public playerController: SubscribedAbstractProperty<WDPlayerController> = AppStorage.link<WDPlayerController>('playerController')
  14 + public floatWindowClass: SubscribedAbstractProperty<window.Window> = AppStorage.link<window.Window>('floatWindowClass')
  15 + public srcTitle: string = ''
  16 + private url: string = ''
  17 + // 窗口是否最小化
  18 + private isMinimize: SubscribedAbstractProperty<boolean> = AppStorage.link<boolean>('isMinimize')
  19 + constructor() {
  20 + this.initPlayerController()
  21 + }
  22 + /**
  23 + * 判断音频实例是否已存在,不存在则创建
  24 + */
  25 + private initPlayerController() {
  26 + if(this.playerController === undefined) {
  27 + // Logger.info(TAG, 'playerController undefined')
  28 + AppStorage.setOrCreate('playerController', new WDPlayerController({loop: false}));
  29 + this.playerController = AppStorage.link<WDPlayerController>('playerController')
  30 + // Logger.info(TAG, 'playerController create success')
  31 + this.playerController.get().onStatusChange = (status: number) => {
  32 + // console.info(TAG, 'this.currentStatus Model', status)
  33 + EmitterUtils.sendEvent(EmitterEventId.AUDIO_CHANGE_STATUS, status)
  34 + }
  35 + } else {
  36 + // Logger.info(TAG, 'playerController already exit')
  37 + }
  38 + }
  39 + /**
  40 + * 配置音频地址
  41 + */
  42 + public async setPlayerUrl(url: string, srcTitle: string, srcContentId?: string, srcSource?: string) {
  43 + /*console.log(TAG,'this.url', this.url)
  44 + console.log(TAG,'url', url)*/
  45 + this.playerController.get().keepOnBackground = true
  46 + BackgroundAudioController.sharedController().avplayerController = this.playerController.get()
  47 + await BackgroundAudioController.sharedController().createSession()
  48 + // BackgroundAudioController.sharedController().startContinuousTask()
  49 + BackgroundAudioController.sharedController().listenPlayEvents()
  50 + await BackgroundAudioController.sharedController().setSessionMetaData(srcContentId ?? "", srcTitle, $r("app.media.system_audio_icon_bk_center"), srcSource ?? "")
  51 + BackgroundAudioController.sharedController().stopUseFeatures()
  52 +
  53 + if (this.url === url) {
  54 + this.isMinimize = AppStorage.link<boolean>('isMinimize')
  55 + // console.log(TAG, 'this.isMinimize', this.isMinimize?.get())
  56 + if (this.isMinimize?.get()) {
  57 + EmitterUtils.sendEvent(EmitterEventId.AUDIO_WINDOW_EXPAND, 1)
  58 + AppStorage.setOrCreate('isMinimize', false);
  59 + this.playerController.get().resetPlay()
  60 + } else {
  61 + this.playerController.get().switchPlayOrPause()
  62 + }
  63 + } else {
  64 + this.url = url
  65 + this.playerController.get().firstPlay(url)
  66 + this.playerController.get().onCanplay = () => {
  67 + this.playerController.get().play()
  68 + }
  69 + this.srcTitle = srcTitle
  70 + EmitterUtils.sendEvent(EmitterEventId.AUDIO_CHANGE_TITLe, this.srcTitle)
  71 + EmitterUtils.sendEvent(EmitterEventId.AUDIO_WINDOW_EXPAND, 1)
  72 + }
  73 + this.showWindow()
  74 + }
  75 + // 显示悬浮窗。
  76 + public showWindow() {
  77 + // 判断当前窗口是否已显示,使用callback异步回调。
  78 + this.floatWindowClass.get().isShowing((err: BusinessError, data) => {
  79 + const errCode: number = err.code;
  80 + if (errCode) {
  81 + // console.error(TAG, 'Failed window is showing Cause:' + JSON.stringify(err));
  82 + return;
  83 + }
  84 + // console.info(TAG, 'window is showing: ' + JSON.stringify(data));
  85 + if(data === false) {
  86 + // 显示当前窗口,使用callback异步回调。
  87 + this.floatWindowClass.get().showWindow((err: BusinessError) => {
  88 + let errCode: number = err.code;
  89 + if (errCode) {
  90 + // console.error(TAG, 'floatWindowClass Failed to show the window. Cause: ' + JSON.stringify(err));
  91 + return;
  92 + }
  93 + // console.info(TAG, 'floatWindowClass Succeeded in showing the window.');
  94 + });
  95 + }
  96 + });
  97 + }
  98 +
  99 + // 设置悬浮窗尺寸
  100 + public resizeWindow(width: number, height: number) {
  101 + this.floatWindowClass.get().resize(width, height, (err: BusinessError) => {
  102 + let errCode: number = err.code;
  103 + if (errCode) {
  104 + // console.error(TAG, 'floatWindowClass Failed to change the window size. Cause:' + JSON.stringify(err));
  105 + return;
  106 + }
  107 + // console.info(TAG, 'floatWindowClass Succeeded in changing the window size.');
  108 + });
  109 + }
  110 +
  111 + // 隐藏悬浮窗
  112 + public minimize() {
  113 + this.floatWindowClass.get().minimize((err: BusinessError) => {
  114 + const errCode: number = err.code;
  115 + if (errCode) {
  116 + // console.error(TAG, 'Failed to minimize the window. Cause: ' + JSON.stringify(err));
  117 + return;
  118 + }
  119 + AppStorage.setOrCreate('isMinimize', true);
  120 + // console.info(TAG, 'Succeeded in minimizing the window.');
  121 + });
  122 + }
  123 +
  124 +
  125 +
  126 +}