KEMBAR78
Media Playback Customization in HybridWebView · Issue #30846 · dotnet/maui · GitHub
Skip to content

Media Playback Customization in HybridWebView #30846

@mattleibow

Description

@mattleibow

Objective

Define the required options and API changes to support media playback customization in HybridWebView, for features such as:

  • Inline video playback (playsInline)
  • Autoplay video/audio content (autoplay)
  • AirPlay and Picture-in-Picture support
  • User gesture requirements for media playback

Scope

  • Identify platform-specific APIs and settings for iOS, Android, and Windows.
  • Specify which playback options should be configurable.
  • Determine whether these options should be available globally, per-WebView, or both.

Requirements

  • List all media playback options to support.
  • Describe expected developer experience (e.g., API surface, usage).
  • Document platform-specific differences and limitations.
  • Include migration notes for existing users.

Platform References & Samples

iOS / MacCatalyst

#if IOS || MACCATALYST
HybridWebView.HybridWebViewHandler.PlatformViewFactory = (handler) => {

    var config = new WKWebViewConfiguration();

    // CUSTOM CONFIG
    config.AllowsAirPlayForMediaPlayback = true;
    config.AllowsInlineMediaPlayback = true;
    config.AllowsPictureInPictureMediaPlayback = true;
    config.MediaTypesRequiringUserActionForPlayback = WebKit.WKAudiovisualMediaTypes.None;

    // Developer extras
    var enableWebDevTools = ((HybridWebView.HybridWebView)(handler as HybridWebViewHandler).VirtualView).EnableWebDevTools;
    config.Preferences.SetValueForKey(NSObject.FromObject(enableWebDevTools), new NSString("developerExtrasEnabled"));
    var platformView = new MauiWKWebView(RectangleF.Empty, handler as HybridWebViewHandler, config);

    if (OperatingSystem.IsMacCatalystVersionAtLeast(13, 3) ||
        OperatingSystem.IsIOSVersionAtLeast(16, 4)) {
        platformView.SetValueForKey(NSObject.FromObject(enableWebDevTools), new NSString("inspectable"));
    }

    return platformView;
};
#endif

Windows

#if WINDOWS
Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--autoplay-policy=no-user-gesture-required");
#endif

Android

#if ANDROID
webView.HandlerChanged += delegate {
    var platformView = (webView.Handler as HybridWebViewHandler).PlatformView;
    platformView.Settings.MediaPlaybackRequiresUserGesture = false; // Forces autoplay

    // Permission client setup omitted for brevity
};
#endif

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions