tryphotino / photino.NET

https://tryphotino.io
Apache License 2.0
885 stars 73 forks source link

Media autoPlay policy Required #142

Closed hejiajun107 closed 10 months ago

hejiajun107 commented 1 year ago

Since the webview disabled miedia autoplay by default,need some option to enabled this wihout user gesture. Like the comandline args in chrome --autoplay-policy=no-user-gesture-required or like android webview option mediaPlaybackRequiresUserGesture

philippjbauer commented 11 months ago

Hi @hejiajun107!

We added a way to pass init flags to the browser control in Photino.NET v2.5.0 (just released). You can try to pass --autoplay-policy=no-user-gesture-required as a string via the SetBrowserControlInitParameters method.

public class Program
{
    public static void Main(string[] args)
    {
        string browserControlInitParams = string.Empty;

        if (PhotinoWindow.IsWindowsPlatform)
        {
            // Windows specific initialization parameters
            browserControlInitParams = "--flag --option-with-value=value";
        }
        else if (PhotinoWindow.IsMacOsPlatform)
        {
            // macOS specific initialization parameters
            browserControlInitParams = JsonSerializer.Serialize(new
            {
                flag = true,
                optionWithValue = "value"
            });
        }
        else if (PhotinoWindow.IsLinuxPlatform)
        {
            // Linux specific initialization parameters
            browserControlInitParams = JsonSerializer.Serialize(new
            {
                flag = true,
                optionWithValue = "value"
            });
        }

        PhotinoWindow window = new PhotinoWindow()
            .SetTitle("Photino Testing")
            .SetBrowserControlInitParameters(browserControlInitParams)
            .LoadRawString("Hello World!");

        window.WaitForClose();
    }
}

Please let us know if this resolves your issue!

hejiajun107 commented 10 months ago

It works

philippjbauer commented 10 months ago

Thank you for confirming this @hejiajun107!