1

How do I enable audio/sound of web media in cefsharp offscreen? When using cefsharp winform, it works fine. audis is running.

However, I must use it offscreen, so I have changed from winform to offscreen. Thereafter, a failure audio running. Media audio is played using webRTC.

This is the CefSettings c# code.

CefSettings settings = new CefSettings();
CefSharpSettings.LegacyJavascriptBindingEnabled = true; // Enable Register JS Object, -- RegisterAsyncJsObject, RegisterJsObject allow

settings.CachePath = "cache";
settings.CefCommandLineArgs.Add("enable-media-stream", "1"); //Enable WebRTC

//NOTE: The following function will set all three params
settings.CefCommandLineArgs.Add("disable-gpu", "1");
settings.CefCommandLineArgs.Add("disable-gpu-compositing", "1");

//NOTE: The Custom Scheme set up to embedded resources
settings.RegisterScheme(new CefCustomScheme()
{
   SchemeName = ResourceSchemeHandlerFactory.SchemeName,
   SchemeHandlerFactory = new ResourceSchemeHandlerFactory()
});

Cef.Initialize(settings);

This is browserSettings code.

BrowserSettings browserSettings = new BrowserSettings();
browserSettings.FileAccessFromFileUrls = CefState.Enabled;
browserSettings.UniversalAccessFromFileUrls = CefState.Enabled;
browserSettings.WebSecurity = CefState.Disabled;

nxBrowser = new ChromiumWebBrowser("resource://web/nxwebRTCAPI.html", browserSettings);
nxBrowser.RegisterJsObject("callBackObj", this);

and this is the html source.

<body>
    <script src="js/nxWebApi.js"></script>
    <script src="js/nxCallBack.js"></script>

    <audio id="audio_remote" autoplay="autoplay"> </audio>
</body>
</html>

Please check my problems in the code.

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
JinoKiM
  • 11
  • 1
  • 3
  • audio is muted by default in `69.0.0`, see https://github.com/cefsharp/CefSharp/commit/e08e882c909f5559e8e42b015bc410415cd2666b#diff-2ecfdb174bf6b80d52f7840086accb73 you just need to remove the entry from `CefCommandLineArgs`. – amaitland Nov 22 '18 at 01:01
  • 1
    @amaitland thanks to you, I solved it. but i using cefsharp.offscreen version is `67.0.0`. in the `67.0.0` seems to have a audio is muted by default. I modified the CefSettings code and solved it. This is the code. `settings.CefCommandLineArgs.Remove("mute-audio");` – JinoKiM Nov 22 '18 at 01:53
  • You are correct, it should have been `67.0.0`. Remember it's open source, so rather than guessing you can just look at the code, see https://github.com/cefsharp/CefSharp/blob/cefsharp/67/CefSharp.OffScreen/CefSettings.cs – amaitland Nov 22 '18 at 02:43

0 Answers0