From 68b497d3a55383368b884549c0fdd564726677c4 Mon Sep 17 00:00:00 2001 From: Lei Gao Date: Thu, 2 Mar 2023 11:57:17 +0800 Subject: [PATCH] [WebView] Supports mute the web page. 1. Supports to mute the web page. 2. Supports to observe the audio/video playing state on the web page. Signed-off-by: Lei Gao --- .../reference/apis/js-apis-webview.md | 38 +++++++++++++++++++ .../arkui-ts/ts-basic-components-web.md | 34 +++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/zh-cn/application-dev/reference/apis/js-apis-webview.md b/zh-cn/application-dev/reference/apis/js-apis-webview.md index bb45a00e16..d59bab84d8 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-webview.md +++ b/zh-cn/application-dev/reference/apis/js-apis-webview.md @@ -3572,6 +3572,44 @@ struct Index { } ``` +### setAudioMuted + +setAudioMuted(mute: boolean): void + +设置网页静音。 + +**系统能力:** SystemCapability.Web.Webview.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------- | ---- | -------------------------------------- | +| mute | boolean | 是 | 表示是否将网页设置为静音状态,true表示设置为静音状态,false表示取消静音状态。 | + +**示例:** + +```ts +// xxx.ets +import web_webview from '@ohos.web.webview' + +@Entry +@Component +struct WebComponent { + controller: web_webview.WebviewController = new web_webview.WebviewController() + @State muted: boolean = false + build() { + Column() { + Button("Toggle Mute") + .onClick(event => { + this.muted = !this.muted + this.controller.setAudioMuted(this.muted) + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +``` + ## WebCookieManager 通过WebCookie可以控制Web组件中的cookie的各种行为,其中每个应用中的所有web组件共享一个WebCookieManager实例。 diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md index da0b5198c1..7059d1f5eb 100755 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md @@ -2861,6 +2861,40 @@ onFaviconReceived(callback: (event: {favicon: image.PixelMap}) => void) } ``` +### onAudioStateChanged10+ + +onAudioStateChanged(callback: (event: { playing: boolean }) => void) + +设置网页上的音频播放状态发生改变时的回调函数。 + +**参数:** + +| 参数名 | 参数类型 | 参数描述 | +| ------- | ---------------------------------------------- | ----------------------------------- | +| playing | boolean | 当前页面的音频播放状态,true表示正在播放,false表示未播放。 | + +**示例:** + + ```ts + // xxx.ets + import web_webview from '@ohos.web.webview' + @Entry + @Component + struct WebComponent { + controller: web_webview.WebviewController = new web_webview.WebviewController() + @State playing: boolean = false + build() { + Column() { + Web({ src:'www.example.com', controller: this.controller }) + .onAudioStateChanged(event => { + this.playing = event.playing + console.debug('onAudioStateChanged playing: ' + this.playing) + }) + } + } + } + ``` + ## ConsoleMessage Web组件获取控制台信息对象。示例代码参考[onConsole事件](#onconsole)。 -- GitLab