王士厅

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

... ... @@ -20,23 +20,23 @@
"name": "default",
"type": "HarmonyOS",
"material": {
"certpath": "./singing_config/manual_com.peopledailychina.hosactivity_sign/鸿蒙中文版客户端证书.cer",
"storePassword": "0000001E857CAD6D7E7172B6C87426344CEF8CC3281AB0461B4FA467DA64A1E11BD35929D150343E5D8E1EEE2740",
"keyAlias": "peopledailyhosalias",
"keyPassword": "0000001E383EA87F51D8B158D5D1FC9ACC10179A0C93E81FD01B2E24D5B449EF1E50789BCEBC4FA09E3E5445C12A",
"profile": "./singing_config/manual_com.peopledailychina.hosactivity_sign/peopledaiychina-hos-profile-debugDebug.p7b",
"certpath": "C:\\Users\\Thurman\\.ohos\\config\\default_sight_harmony_QWBSqgX-h8PHbOj8MRnxCwvXCUltlp6P5ebKMKA51TI=.cer",
"storePassword": "00000019007D1BE372F9267A310C953AEA12FDB4353D441C310E4A4611BFEC577D837C9530B345C64D",
"keyAlias": "debugKey",
"keyPassword": "00000019D1436C0369AD6985BD560FAE6620037BB413CBE4E84AE05AD76BC45E637F5FB1E101B70922",
"profile": "C:\\Users\\Thurman\\.ohos\\config\\default_sight_harmony_QWBSqgX-h8PHbOj8MRnxCwvXCUltlp6P5ebKMKA51TI=.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "./singing_config/manual_com.peopledailychina.hosactivity_sign/keystorefile.p12"
"storeFile": "C:\\Users\\Thurman\\.ohos\\config\\default_sight_harmony_QWBSqgX-h8PHbOj8MRnxCwvXCUltlp6P5ebKMKA51TI=.p12"
}
},
{
"name": "release",
"type": "HarmonyOS",
"material": {
"storePassword": "0000001E423C7B1ED6AA1EC296F8E9D84C03F7D2E2BD770655E9EABA798E457E15B4D993CCA36416B0200E92DED7",
"certpath": "./singing_config/manual_com.peopledailychina.hosactivity_sign/鸿蒙中文版客户端证书正式.cer",
"storePassword": "0000001E4D643D92F70DFDD813B928597AD5724094204DEB350DE798DBC2FBDAD97C54B58B01CC1B1756F6ED5EDE",
"keyAlias": "peopledailyhosalias",
"keyPassword": "0000001E9C2E794B52FC032F4C6ED037D72ADAAC76F3F0F001342A7D79ABE3A45E01FA86911A0510DB2B532847E2",
"keyPassword": "0000001E33EC19E6AB58A6E4968586FEAB93B0990CA5A204048F4630232D6C77A89B5919EC9545ADDA7B4BB56BB4",
"profile": "./singing_config/manual_com.peopledailychina.hosactivity_sign/peopledailychina-hos-profile-releaseRelease.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "./singing_config/manual_com.peopledailychina.hosactivity_sign/keystorefile.p12"
... ... @@ -56,7 +56,9 @@
"BUILD_VERSION": ""
}
},
"strictMode": {"useNormalizedOHMUrl": true}
"strictMode": {
"useNormalizedOHMUrl": true
}
},
},
{
... ... @@ -71,7 +73,9 @@
"BUILD_VERSION": ""
}
},
"strictMode": {"useNormalizedOHMUrl": true}
"strictMode": {
"useNormalizedOHMUrl": true
}
}
}
],
... ...
... ... @@ -7,6 +7,8 @@ import { Message } from 'wdJsBridge/src/main/ets/bean/Message';
import { DateTimeUtils,EmitterUtils,EmitterEventId } from 'wdKit'
import { window } from '@kit.ArkUI';
import { NativeCallH5Type,NativeCallH5Event,eventParams } from './NativeCallH5Type';
import { AudioSuspensionModel } from '../viewmodel/AudioSuspensionModel'
import { BusinessError } from '@kit.BasicServicesKit';
const TAG = 'WdWebLocalComponent';
... ... @@ -44,6 +46,8 @@ export struct WdWebLocalComponent {
@Consume @Watch('pageShowForUpdateData') pageShow :number
@Consume @Watch('pageHideForUpdateData') pageHide :number
private AudioSuspension = new AudioSuspensionModel()
currentChanged(){
///折叠屏转换 暂停播放器
this.controller.pause()
... ... @@ -186,6 +190,19 @@ export struct WdWebLocalComponent {
}
}
}
// 暂停音频悬浮窗
pauseAudioCom() {
// 判断当前窗口是否已显示,使用callback异步回调。
this.AudioSuspension.floatWindowClass.get().isShowing((err: BusinessError, data) => {
const errCode: number = err.code;
if (errCode) {
return;
}
if(data) {
this.AudioSuspension.playerController.get()?.pause();
}
});
}
//播放视频
private setCurrentPageOperate9: (data: Message) => void = (data) => {
if (data.handlerName === H5CallNativeType.jsCall_currentPageOperate && data?.data?.operateType === '9') {
... ... @@ -235,6 +252,7 @@ export struct WdWebLocalComponent {
this.cancelProgressTimer()
this.controller.start()
this.startProgressTimer()
this.pauseAudioCom()
}
startProgressTimer() {
... ...
import window from '@ohos.window';
import { Logger } from 'wdKit';
import { BackgroundAudioController, WDPlayerController } from 'wdPlayer';
import { BusinessError } from '@ohos.base';
import { EmitterEventId, EmitterUtils } from 'wdKit/Index'
const TAG = 'AudioSuspensionModel'
/**
* 音频悬浮窗公共方法类
*/
export class AudioSuspensionModel {
public playerController: SubscribedAbstractProperty<WDPlayerController> = AppStorage.link<WDPlayerController>('playerController')
public floatWindowClass: SubscribedAbstractProperty<window.Window> = AppStorage.link<window.Window>('floatWindowClass')
public srcTitle: string = ''
private url: string = ''
// 窗口是否最小化
private isMinimize: SubscribedAbstractProperty<boolean> = AppStorage.link<boolean>('isMinimize')
constructor() {
this.initPlayerController()
}
/**
* 判断音频实例是否已存在,不存在则创建
*/
private initPlayerController() {
if(this.playerController === undefined) {
// Logger.info(TAG, 'playerController undefined')
AppStorage.setOrCreate('playerController', new WDPlayerController({loop: false}));
this.playerController = AppStorage.link<WDPlayerController>('playerController')
// Logger.info(TAG, 'playerController create success')
this.playerController.get().onStatusChange = (status: number) => {
// console.info(TAG, 'this.currentStatus Model', status)
EmitterUtils.sendEvent(EmitterEventId.AUDIO_CHANGE_STATUS, status)
}
} else {
// Logger.info(TAG, 'playerController already exit')
}
}
/**
* 配置音频地址
*/
public async setPlayerUrl(url: string, srcTitle: string, srcContentId?: string, srcSource?: string) {
/*console.log(TAG,'this.url', this.url)
console.log(TAG,'url', url)*/
this.playerController.get().keepOnBackground = true
BackgroundAudioController.sharedController().avplayerController = this.playerController.get()
await BackgroundAudioController.sharedController().createSession()
// BackgroundAudioController.sharedController().startContinuousTask()
BackgroundAudioController.sharedController().listenPlayEvents()
await BackgroundAudioController.sharedController().setSessionMetaData(srcContentId ?? "", srcTitle, $r("app.media.system_audio_icon_bk_center"), srcSource ?? "")
BackgroundAudioController.sharedController().stopUseFeatures()
if (this.url === url) {
this.isMinimize = AppStorage.link<boolean>('isMinimize')
// console.log(TAG, 'this.isMinimize', this.isMinimize?.get())
if (this.isMinimize?.get()) {
EmitterUtils.sendEvent(EmitterEventId.AUDIO_WINDOW_EXPAND, 1)
AppStorage.setOrCreate('isMinimize', false);
this.playerController.get().resetPlay()
} else {
this.playerController.get().switchPlayOrPause()
}
} else {
this.url = url
this.playerController.get().firstPlay(url)
this.playerController.get().onCanplay = () => {
this.playerController.get().play()
}
this.srcTitle = srcTitle
EmitterUtils.sendEvent(EmitterEventId.AUDIO_CHANGE_TITLe, this.srcTitle)
EmitterUtils.sendEvent(EmitterEventId.AUDIO_WINDOW_EXPAND, 1)
}
this.showWindow()
}
// 显示悬浮窗。
public showWindow() {
// 判断当前窗口是否已显示,使用callback异步回调。
this.floatWindowClass.get().isShowing((err: BusinessError, data) => {
const errCode: number = err.code;
if (errCode) {
// console.error(TAG, 'Failed window is showing Cause:' + JSON.stringify(err));
return;
}
// console.info(TAG, 'window is showing: ' + JSON.stringify(data));
if(data === false) {
// 显示当前窗口,使用callback异步回调。
this.floatWindowClass.get().showWindow((err: BusinessError) => {
let errCode: number = err.code;
if (errCode) {
// console.error(TAG, 'floatWindowClass Failed to show the window. Cause: ' + JSON.stringify(err));
return;
}
// console.info(TAG, 'floatWindowClass Succeeded in showing the window.');
});
}
});
}
// 设置悬浮窗尺寸
public resizeWindow(width: number, height: number) {
this.floatWindowClass.get().resize(width, height, (err: BusinessError) => {
let errCode: number = err.code;
if (errCode) {
// console.error(TAG, 'floatWindowClass Failed to change the window size. Cause:' + JSON.stringify(err));
return;
}
// console.info(TAG, 'floatWindowClass Succeeded in changing the window size.');
});
}
// 隐藏悬浮窗
public minimize() {
this.floatWindowClass.get().minimize((err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
// console.error(TAG, 'Failed to minimize the window. Cause: ' + JSON.stringify(err));
return;
}
AppStorage.setOrCreate('isMinimize', true);
// console.info(TAG, 'Succeeded in minimizing the window.');
});
}
}
\ No newline at end of file
... ...