应用内通过悬浮窗进行音频播放控制,
1、如何将页面数据传递到悬浮窗中,将当前页面中的数据传递到FloatContent页面中去。
2、悬浮窗和播放页面双向变更刷新。
// 为悬浮窗加载页面内容,这里可以设置在main_pages.json中配置的页面
win.setUIContent("pages/floatwindow/view/FloatContent", (err: BusinessError) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
win.setWindowBackgroundColor("#00000000")
console.info('Succeeded in loading the content.');
// 显示悬浮窗。
win.showWindow((err: BusinessError) => {
if (err.code) {
console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in showing the window.');
});
});
可以使用页面级状态存储,可以使用loadContent(path: string, storage: LocalStorage)方法加载新页面并通过lcoalStorage传递参数,在新页面中通过LocalStorage.getShared()获取传入的lcoalStorage。
参考文档如下:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5\#loadcontent9
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-localstorage-V5