Skip to content

Commit

Permalink
Merge pull request #252 from adamkobor/akobor/video-playback-improvem…
Browse files Browse the repository at this point in the history
…ents

video playback improvements
  • Loading branch information
KevinnZou authored Nov 18, 2024
2 parents 3e95ced + ef3f0e2 commit 3e6a565
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3e6a565

Please sign in to comment.