From d9e3e270a6a8fd010fa6ee58a68a7581aa90d28a Mon Sep 17 00:00:00 2001 From: wuzhiming Date: Tue, 23 Jul 2024 16:09:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20webview=20=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=AD=97=E4=BD=93=E5=A4=A7=E5=B0=8F=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuzhiming --- .../io.flutter.plugins/webview_flutter/OhosWebView.ets | 7 ++++++- .../webview_flutter/WebSettingsHostApiImpl.ets | 2 ++ .../webview_flutter/WebViewHostApiImpl.ets | 8 ++++++++ .../io.flutter.plugins/webview_flutter/OhosWebView.ets | 7 ++++++- .../webview_flutter/WebSettingsHostApiImpl.ets | 2 ++ .../webview_flutter/WebViewHostApiImpl.ets | 6 ++++++ 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/OhosWebView.ets b/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/OhosWebView.ets index 81ce60067..27f7bfbf2 100644 --- a/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/OhosWebView.ets +++ b/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/OhosWebView.ets @@ -24,8 +24,13 @@ export struct OhosWebView { webView: WebViewPlatformView = this.params.platformView as WebViewPlatformView; controller: web_webview.WebviewController = this.webView.getController(); + @State textZoomRatio: number = this.webView.getWebSettings().getTextZoom(); + aboutToAppear() { this.webView.getWebSettings().setSupportZoom(true); + this.webView.getWebSettings().onTextZoomChanged((ratio: number) => { + this.textZoomRatio = ratio; + }); } build() { @@ -57,7 +62,7 @@ export struct OhosWebView { .overviewModeAccess(this.webView.getWebSettings().getLoadWithOverviewMode()) .wideViewModeAccess(this.webView.getWebSettings().getUseWideViewPort()) .fileAccess(this.webView.getWebSettings().getAllowFileAccess()) - .textZoomRatio(this.webView.getWebSettings().getTextZoom()) + .textZoomRatio(this.textZoomRatio) .onScroll(this.webView.onScroll) .onControllerAttached(this.webView.onControllerAttached) .overScrollMode(OverScrollMode.ALWAYS) diff --git a/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebSettingsHostApiImpl.ets b/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebSettingsHostApiImpl.ets index e7ee2d5d5..388420aeb 100644 --- a/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebSettingsHostApiImpl.ets +++ b/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebSettingsHostApiImpl.ets @@ -69,6 +69,8 @@ export interface WebSettings { getTextZoom(): number; getUserAgentString(): Promise + + onTextZoomChanged(callback: (ratio: number) => void): void; } export class WebSettingsCreator { diff --git a/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebViewHostApiImpl.ets b/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebViewHostApiImpl.ets index f95b13179..62f6209be 100644 --- a/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebViewHostApiImpl.ets +++ b/packages/webview_flutter-v4.4.4/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebViewHostApiImpl.ets @@ -503,6 +503,8 @@ class WebSettingsImpl implements WebSettings { wideViewModeAccess: boolean = false; fileAccess : boolean = false; textZoomRatio : number = 0; + textZoomRatioCallback?: (ratio: number) => void; + constructor(webView: WebViewPlatformView) { this.webView = webView; @@ -605,6 +607,7 @@ class WebSettingsImpl implements WebSettings { setTextZoom(textZoom: number) { this.textZoomRatio = textZoom; + this.textZoomRatioCallback && this.textZoomRatioCallback(textZoom); } async getUserAgentString(): Promise { @@ -615,4 +618,9 @@ class WebSettingsImpl implements WebSettings { getTextZoom() : number{ return this.textZoomRatio; } + + onTextZoomChanged(callback: (ratio: number) => void): void { + this.textZoomRatioCallback = callback; + } + } \ No newline at end of file diff --git a/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/OhosWebView.ets b/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/OhosWebView.ets index 98cd5db97..ec0220326 100644 --- a/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/OhosWebView.ets +++ b/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/OhosWebView.ets @@ -24,8 +24,13 @@ export struct OhosWebView { webView: WebViewPlatformView = this.params.platformView as WebViewPlatformView; controller: web_webview.WebviewController = this.webView.getController(); + @State textZoomRatio: number = this.webView.getWebSettings().getTextZoom(); + aboutToAppear() { this.webView.getWebSettings().setSupportZoom(true); + this.webView.getWebSettings().onTextZoomChanged((ratio: number) => { + this.textZoomRatio = ratio; + }); } build() { @@ -57,7 +62,7 @@ export struct OhosWebView { .overviewModeAccess(this.webView.getWebSettings().getLoadWithOverviewMode()) .wideViewModeAccess(this.webView.getWebSettings().getUseWideViewPort()) .fileAccess(this.webView.getWebSettings().getAllowFileAccess()) - .textZoomRatio(this.webView.getWebSettings().getTextZoom()) + .textZoomRatio(this.textZoomRatio) .onScroll(this.webView.onScroll) .onControllerAttached(this.webView.onControllerAttached) .overScrollMode(OverScrollMode.ALWAYS) diff --git a/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebSettingsHostApiImpl.ets b/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebSettingsHostApiImpl.ets index 4ca37028c..1f7d17832 100644 --- a/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebSettingsHostApiImpl.ets +++ b/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebSettingsHostApiImpl.ets @@ -70,6 +70,8 @@ export interface WebSettings { getUserAgentString(): string; + + onTextZoomChanged(callback: (ratio: number) => void): void; } export class WebSettingsCreator { diff --git a/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebViewHostApiImpl.ets b/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebViewHostApiImpl.ets index cd83597eb..a46733dfe 100644 --- a/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebViewHostApiImpl.ets +++ b/packages/webview_flutter/webview_flutter_ohos/ohos/src/main/ets/io.flutter.plugins/webview_flutter/WebViewHostApiImpl.ets @@ -535,6 +535,7 @@ class WebSettingsImpl implements WebSettings { wideViewModeAccess: boolean = false; fileAccess : boolean = false; textZoomRatio : number = 0; + textZoomRatioCallback?: (ratio: number) => void; constructor(webView: WebViewPlatformView) { this.webView = webView; @@ -638,6 +639,7 @@ class WebSettingsImpl implements WebSettings { setTextZoom(textZoom: number) { this.textZoomRatio = textZoom; + this.textZoomRatioCallback && this.textZoomRatioCallback(textZoom); } getUserAgentString(): string { @@ -649,4 +651,8 @@ class WebSettingsImpl implements WebSettings { return this.textZoomRatio; } + onTextZoomChanged(callback: (ratio: number) => void): void { + this.textZoomRatioCallback = callback; + } + } \ No newline at end of file -- Gitee From fbb6cd821536ba82bdbbf4d6c1dfb57096231c10 Mon Sep 17 00:00:00 2001 From: wuzhiming Date: Tue, 23 Jul 2024 17:57:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20video=5Fplayer?= =?UTF-8?q?=20=E6=92=AD=E6=94=BE=E7=9B=B4=E6=92=AD=E6=B5=81=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=97=B6=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuzhiming --- .../src/main/ets/components/videoplayer/VideoPlayer.ets | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/video_player/video_player_ohos/ohos/src/main/ets/components/videoplayer/VideoPlayer.ets b/packages/video_player/video_player_ohos/ohos/src/main/ets/components/videoplayer/VideoPlayer.ets index 9ffe26bbe..3e6527f83 100644 --- a/packages/video_player/video_player_ohos/ohos/src/main/ets/components/videoplayer/VideoPlayer.ets +++ b/packages/video_player/video_player_ohos/ohos/src/main/ets/components/videoplayer/VideoPlayer.ets @@ -182,8 +182,13 @@ export class VideoPlayer { this.sendBufferingUpdate(infoType, value); }); - this.avPlayer.on(Events.ERROR, (err: Object) => { + this.avPlayer.on(Events.ERROR, (err: BusinessError) => { Log.e(TAG, "avPlayer Events.ERROR: " + JSON.stringify(err)); + // 播放直播视频时,设置 loop 会报错,而 loop 一定会设置(video_player.dart 中初始化之后会 _applyLooping),所以屏蔽掉该报错 + // message: Unsupport Capability: The stream is live stream, not support loop + if(err.code == 801) { + return; + } this.avPlayer?.reset(); this.sendError(err); }) -- Gitee