Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Mute audio on instance based ?

Post Reply
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Mute audio on instance based ?

Post by thefunkyjoint »

I know i can mute audio using this method :

GlobalCEFApp.MuteAudio := true

But this will mute audio for all instances of ChromiunWindow i create on my app.

Is there a way to mute just a specific instance ?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Mute audio on instance based ?

Post by salvadordf »

Try setting TChromiumCore.AudioMuted := True;

That property can only be read in the "UI" CEF thread. That's why the MiniBrowser demo uses the context menu to mute the audio of that browser :
https://github.com/salvadordf/CEF4Delphi/blob/15f51eccc759d893462b9068d97cc5b70c2d88f8/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L589
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Mute audio on instance based ?

Post by thefunkyjoint »

Thank you ! :D
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Mute audio on instance based ?

Post by thefunkyjoint »

For youtube this method does not work. I used this method after creating the component, but even so the video sound is playing normally. Maybe you need to call this method after the page loads ? It it's the case, i could do the same thing using pure JS, my goal is to silence sound for any page loaded, but only in a specific instance of TChromiumWindow.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Mute audio on instance based ?

Post by salvadordf »

I just tested a YouTube video with MiniBrowser and the context menu to mute the audio works correctly.

This means that both the setter and the getter functions for the TChromiumCore.MuteAudio property need to be called in the CEF UI thread.

I'll modify the setter to make sure it's executed in the correct thread.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Mute audio on instance based ?

Post by salvadordf »

Download CEF4Delphi again.

There's a new TChromiumCore.ToggleAudioMuted function used to enable and disable the audio in that browser. You can call this function from any thread.

Now the TChromiumCore.AudioMuted setter can be called from any thread but if you want to read the value of that property you'll need to do that from the CEF UI thread.
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Mute audio on instance based ?

Post by thefunkyjoint »

Ok, will give it a try tonight, thank you !
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Mute audio on instance based ?

Post by thefunkyjoint »

Now it's working, thanks ! :D
Post Reply