Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoplay in Webview2 #19096

Open
ForkBug opened this issue Dec 17, 2024 · 1 comment
Open

Autoplay in Webview2 #19096

ForkBug opened this issue Dec 17, 2024 · 1 comment
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/enhancement New feature or request triage/untriaged Indicates an issue requires triaging or verification

Comments

@ForkBug
Copy link

ForkBug commented Dec 17, 2024

What would you like to be added

Implement methods for playsinline, autoplay, and other playback configuration options.

Why is this needed

Allow autoplay, inline play, other possible platform specific playback features as part of the basic build in function.

For which platform

Android, iOS, Mac Catalyst, Skia (WPF), Skia (Linux X11), Skia (macOS), Windows (WinAppSDK)

Anything else we need to know?

There more detailed implement information from dotnet/maui#23747

@ForkBug ForkBug added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/enhancement New feature or request triage/untriaged Indicates an issue requires triaging or verification labels Dec 17, 2024
@ForkBug
Copy link
Author

ForkBug commented Dec 17, 2024

Workaround:
Call EnsureCoreWebView2Async() and then

Android:

public class WebViewCustomization
{
    internal static Android.Webkit.WebView? GetNativeWebViewFromTemplate(Microsoft.UI.Xaml.Controls.WebView2 webView2)
    {
        var webView = (webView2 as ViewGroup)?
            .GetChildren(v => v is Android.Webkit.WebView)
            .FirstOrDefault() as Android.Webkit.WebView;

        return webView;
    }
    public static void SetWebView(Microsoft.UI.Xaml.Controls.WebView2 webView2)
    {
         var web = GetNativeWebViewFromTemplate(webView2);
        if (web==null)
        {
            return;
        }
        web.Settings.MediaPlaybackRequiresUserGesture = false;
    }
}

Windows:

public class WebViewCustomization
{
    public static void SetWebView(Microsoft.UI.Xaml.Controls.WebView2 webView2)
    {
#if !DEBUG
        webView2.CoreWebView2.Settings.AreDevToolsEnabled = false;
#endif
        Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--autoplay-policy=no-user-gesture-required");
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/enhancement New feature or request triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
Development

No branches or pull requests

1 participant