Delphi Media Player Volume Control

I have two mediaplayers in one form, how to get low volume in one mediaplayer and still high in other? Help me
Muhamad PurwantoAsked:
Who is Participating?
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Are you using TmediaPlayer components?
If so you coud do that using MCI

This is a part of code that I use for a little mp3 player application

First the audio control procedure
uses MMSystem;
procedure SetMPVolume(MP : TMediaPlayer; Volume : Integer);
const
  MCI_SETAUDIO               = $0873;
  MCI_DGV_SETAUDIO_VOLUME    = $4002;
  MCI_DGV_SETAUDIO_ITEM      = $00800000;
  MCI_DGV_SETAUDIO_VALUE     = $01000000;

Type
  MCI_DGV_SETAUDIO_PARMS = record
   dwCallback : DWORD;
   dwItem     : DWORd;
   dwValue : DWORD;
   dwOver : DWORD;
   lpstrAlgorithm : PChar;
   lpstrQuality : PChar;
  end;

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;

Open in new window

Then, having 2 TMediaPlayer and 2 TTrackBar on the form, set the properties MAX of the both TTrackBar to 1000 (Min to 0) and change the volume of the 2 MP as follows

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  SetMPVolume(MediaPlayer1, TrackBar1.Position);
end;

procedure TForm1.TrackBar2Change(Sender: TObject);
begin
  SetMPVolume(MediaPlayer2, TrackBar2.Position);
end;

Open in new window

It's just a point of start. Hope it helps
0
 
Muhamad PurwantoAuthor Commented:
It works for me, thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.