diff --git a/webview/src/androidMain/kotlin/com/multiplatform/webview/web/AccompanistWebView.kt b/webview/src/androidMain/kotlin/com/multiplatform/webview/web/AccompanistWebView.kt index 8d6f1ec9..e7f33d3c 100644 --- a/webview/src/androidMain/kotlin/com/multiplatform/webview/web/AccompanistWebView.kt +++ b/webview/src/androidMain/kotlin/com/multiplatform/webview/web/AccompanistWebView.kt @@ -487,4 +487,12 @@ open class AccompanistWebChromeClient : WebChromeClient() { KLogger.d { "onPermissionRequest denied permissions: ${request.resources}" } } } + + override fun getDefaultVideoPoster(): Bitmap? { + return if (state.webSettings.androidWebSettings.hideDefaultVideoPoster) { + Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888) + } else { + super.getDefaultVideoPoster() + } + } } diff --git a/webview/src/commonMain/kotlin/com/multiplatform/webview/setting/PlatformWebSettings.kt b/webview/src/commonMain/kotlin/com/multiplatform/webview/setting/PlatformWebSettings.kt index 1405ea08..cdd58662 100644 --- a/webview/src/commonMain/kotlin/com/multiplatform/webview/setting/PlatformWebSettings.kt +++ b/webview/src/commonMain/kotlin/com/multiplatform/webview/setting/PlatformWebSettings.kt @@ -179,6 +179,10 @@ sealed class PlatformWebSettings { * devices. Available on API level 21 and above. */ var allowMidiSysexMessages: Boolean = false, + /** + * Controls whether the default video poster (a gray, pixelated play button) should be hidden. + */ + var hideDefaultVideoPoster: Boolean = false, /** * The Layer Type of the WebView. * Default is [LayerType.HARDWARE] @@ -243,5 +247,9 @@ sealed class PlatformWebSettings { * Whether the vertical scroll indicator is visible. The default value is {@code true}. */ var showVerticalScrollIndicator: Boolean = true, + /** + * Whether a user gesture is required to play media. The default is {@code true}. + */ + var mediaPlaybackRequiresUserGesture: Boolean = true, ) : PlatformWebSettings() } diff --git a/webview/src/iosMain/kotlin/com/multiplatform/webview/web/WebView.ios.kt b/webview/src/iosMain/kotlin/com/multiplatform/webview/web/WebView.ios.kt index 93aaa474..70493641 100644 --- a/webview/src/iosMain/kotlin/com/multiplatform/webview/web/WebView.ios.kt +++ b/webview/src/iosMain/kotlin/com/multiplatform/webview/web/WebView.ios.kt @@ -14,6 +14,8 @@ import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.readValue import platform.CoreGraphics.CGRectZero import platform.Foundation.setValue +import platform.WebKit.WKAudiovisualMediaTypeAll +import platform.WebKit.WKAudiovisualMediaTypeNone import platform.WebKit.WKWebView import platform.WebKit.WKWebViewConfiguration import platform.WebKit.javaScriptEnabled @@ -84,6 +86,12 @@ fun IOSWebView( val config = WKWebViewConfiguration().apply { allowsInlineMediaPlayback = true + mediaTypesRequiringUserActionForPlayback = + if (state.webSettings.iOSWebSettings.mediaPlaybackRequiresUserGesture) { + WKAudiovisualMediaTypeAll + } else { + WKAudiovisualMediaTypeNone + } defaultWebpagePreferences.allowsContentJavaScript = state.webSettings.isJavaScriptEnabled preferences.apply {