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 :)
Muting or Zeroing Volume via API
Re: Muting or Zeroing Volume via API
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
Re: Muting or Zeroing Volume via API
thanks for that code. i will see if i can get it to work.
Re: Muting or Zeroing Volume via API
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 :)
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 :)
Re: Muting or Zeroing Volume via API
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 wasamazedspeechless :)
Re: Muting or Zeroing Volume via API
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
iMessage