Hello,
I have an application with two MediaPlayers.
MediaPlayer1 I want to play a video and MediaPlayer2 I want to play a sound file.

My problem is that I don't know how to control the sound volume from MediaPlayer1.
How can I set sound volume to zero for MediaPlayer1?

Recommended Answers

All 5 Replies

uses
   MPlayer, MMSystem;
 
 const
   MCI_SETAUDIO = $0873;
   MCI_DGV_SETAUDIO_VOLUME = $4002;
   MCI_DGV_SETAUDIO_ITEM = $00800000;
   MCI_DGV_SETAUDIO_VALUE = $01000000;
   MCI_DGV_STATUS_VOLUME = $4019;
 
 type
   MCI_DGV_SETAUDIO_PARMS = record
     dwCallback: DWORD;
     dwItem: DWORD;
     dwValue: DWORD;
     dwOver: DWORD;
     lpstrAlgorithm: PChar;
     lpstrQuality: PChar;
   end;
 
 type
   MCI_STATUS_PARMS = record
     dwCallback: DWORD;
     dwReturn: DWORD;
     dwItem: DWORD;
     dwTrack: DWORD;
   end;
 
 procedure SetMPVolume(MP: TMediaPlayer; Volume: Integer);
   { Volume: 0 - 1000 }
 var
   p: MCI_DGV_SETAUDIO_PARMS;
 begin
   { Volume: 0 - 1000 }
   p.dwCallback := 0;
   p.dwItem := MCI_DGV_SETAUDIO_VOLUME;
   p.dwValue := Volume;
   p.dwOver := 0;
   p.lpstrAlgorithm := nil;
   p.lpstrQuality := nil;
   mciSendCommand(MP.DeviceID, MCI_SETAUDIO,
     MCI_DGV_SETAUDIO_VALUE or MCI_DGV_SETAUDIO_ITEM, Cardinal(@p));
 end;
 
 function GetMPVolume(MP: TMediaPlayer): Integer;
 var
    p: MCI_STATUS_PARMS;
 begin
   p.dwCallback := 0;
   p.dwItem := MCI_DGV_STATUS_VOLUME;
   mciSendCommand(MP.DeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@p));
   Result := p.dwReturn;
   { Volume: 0 - 1000 }
 end;
 
 // Example, Beispiel: 
 
procedure TForm1.Button1Click(Sender: TObject);
 begin
   SetMPVolume(MediaPlayer1, 500);
 end;

Thanks a lot Wolfgang,
I don't know what DWORD is so to make the compiler happy I replaced them to "word".
Then it compiles and runs, but it has ni invoke on the mediaplayer.

GetMPVolume gives 0 whatever I send through SetMPVolume, and the sound sounds the same.

Any ideas?

Regards
Arne

Help reading have not tried it? DWORD is equivalent to LongWord.

uses
   MPlayer, MMSystem, Types;

or replace DWORD on LongWord. Everything works fine. I attach a file for example.

Help reading have not tried it? DWORD is equivalent to LongWord.

uses
   MPlayer, MMSystem, Types;

or replace DWORD on LongWord. Everything works fine. I attach a file for example.

Perfect!
"Types" made the difference.
Thank you very much.

I found an other solution, that sets right and left volume with just an API call:

uses
...., MMSystem

then
WAVEOUTSETVOLUME(0, $80008000);

Will the suggested code (that also works fine, but I don't understand much of) give any advantages over WAVEOUTSETVOLUME or is WAVEOUTSETVOLUME just as good?

Any ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.