Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
陈剑华
2024-09-23 19:12:51 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
59fb80426a4a1fe81e88bb148fb76fefbe04776c
59fb8042
2 parents
17c5995c
9c6e0c25
Merge remote-tracking branch 'origin/main'
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
1 deletions
sight_harmony/commons/wdWebComponent/oh-package.json5
sight_harmony/commons/wdWebComponent/src/main/ets/pages/WdWebLocalComponent.ets
sight_harmony/commons/wdWebComponent/src/main/ets/viewmodel/AudioSuspensionModel.ets
sight_harmony/commons/wdWebComponent/src/main/resources/base/media/system_audio_icon_bk_center.png
sight_harmony/commons/wdWebComponent/oh-package.json5
View file @
59fb804
...
...
@@ -12,6 +12,7 @@
"wdJsBridge"
:
"file:../wdJsBridge"
,
"wdBean"
:
"file:../../features/wdBean"
,
"wdRouter"
:
"file:../wdRouter"
,
"wdNetwork"
:
"file:../wdNetwork"
"wdNetwork"
:
"file:../wdNetwork"
,
"wdPlayer"
:
"file:../../features/wdPlayer"
}
}
...
...
sight_harmony/commons/wdWebComponent/src/main/ets/pages/WdWebLocalComponent.ets
View file @
59fb804
...
...
@@ -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() {
...
...
sight_harmony/commons/wdWebComponent/src/main/ets/viewmodel/AudioSuspensionModel.ets
0 → 100644
View file @
59fb804
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
...
...
sight_harmony/commons/wdWebComponent/src/main/resources/base/media/system_audio_icon_bk_center.png
0 → 100644
View file @
59fb804
117 KB
Please
register
or
login
to post a comment