Muting or Zeroing Volume via API

Windows specific questions.
Post Reply
xbgtc
Posts: 249
Joined: Oct 14, 2007 5:40
Location: Australia

Muting or Zeroing Volume via API

Post by xbgtc »

Anyone know how to mute the speaker or sound via code?

What i want to do is mute the sound of a video that is playing which uses dshow. Since there is no 'MUTE' command in DSHOW (well that i know off) i have to resort to other ways :)
adeyblue
Posts: 299
Joined: Nov 07, 2019 20:08

Re: Muting or Zeroing Volume via API

Post by adeyblue »

IBasicAudio is where the video volume control is. You get it from the filter graph

Code: Select all

// this is C, it's an example
    hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (void**)&pGraph);
    pGraph->lpVtbl->QueryInterface(pGraph, &IID_IBasicAudio, (void **)&pVolume);
    pVolume->lpVtbl->put_Volume(pVolume, 0); // put it on full blast
xbgtc
Posts: 249
Joined: Oct 14, 2007 5:40
Location: Australia

Re: Muting or Zeroing Volume via API

Post by xbgtc »

thanks for that code. i will see if i can get it to work.
xbgtc
Posts: 249
Joined: Oct 14, 2007 5:40
Location: Australia

Re: Muting or Zeroing Volume via API

Post by xbgtc »

Well, i don't know how the hell i did it but i did it!

I was about to give up as i just don't understand stuff like pGraph->lpVtbl-> but thought i'd atleast make a start by making that pVolume pointer so looking at these dims in my code:

dim as IGraphBuilder Ptr pGraph
dim as IMediaEvent Ptr pEvent
dim as IMediaControl Ptr pControl
dim as IVideoWindow Ptr vidwindow

i just did:

dim as IBasicAudio ptr pVolume

assuming that IbasicAudio must be a type and was the type to use.

Next with pGraph->lpVtbl->QueryInterface(pGraph, &IID_IBasicAudio, (void **)&pVolume);

i had these similiar codes:

hr=IGraphBuilder_QueryInterface(pGraph,@IID_IMediaEvent,@pEvent)
hr=IGraphBuilder_QueryInterface(pGraph,@IID_IMediaControl,@pControl)
hr=IGraphBuilder_QueryInterface(pGraph,@IID_IVideoWindow,@vidwindow)

so did:

hr=IGraphBuilder_QueryInterface(pGraph,@IID_IBasicAudio,@pVolume)

then lastly pVolume->lpVtbl->put_Volume(pVolume, 0);

which is the command so checked out my command codes:

IMediaControl_Pause(pControl)
IMediaControl_Run(pControl)

so did:

IBasicAudio_put_Volume(pVolume,-10000)

and when i ran the program i expected it to error out but to my surprise it ran and the muting or zero volume worked! - i was amazed :)
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Muting or Zeroing Volume via API

Post by dodicat »

xbgtc wrote:Well, i don't know how the hell i did it but i did it!

...

and when i ran the program i expected it to error out but to my surprise it ran and the muting or zero volume worked! - i was amazed speechless :)
xbgtc
Posts: 249
Joined: Oct 14, 2007 5:40
Location: Australia

Re: Muting or Zeroing Volume via API

Post by xbgtc »

haha!
Laurinea
Posts: 1
Joined: Nov 26, 2021 11:37

Re: Muting or Zeroing Volume via API

Post by Laurinea »

I want the video to be muted initially, but if people want they can unmute or increase the volume again. After setting the volume to zero through the API however, the mute button doesn't respond anymore. The volume controls do still work.In onPlayerReady, set the volume to zero to mute the player.Click on the unmute button. Nothing happens.Now increase the volume, and the video does get unmuted.

iMessage
Post Reply