jexd99
asked on
Sound vs. no sound
If I'm playing a video with the mediaplayers, how do I turn the sound off?..... and back on? (D5)
Thanks
Thanks
OK, well, if you are using TMediaPlayer:
The two key functions are waveOutSetVolume and waveOutGetVolume in
MMSystem. The trick is to get the Device ID for use with those
functions. This program uses the MediaPlayer component for that.
WaveOutSetVolume(hwo: Integer; dwVolume: Cardinal);
hwo is MediaPlayer1.DeviceId,
example: Right\/ | Left\/
dwVolume for Full L+R = $FFFFFFFF
dwVolume for Full L no R = $0000FFFF
dwVolume for Full R no L = $FFFF0000
dwVolume for no sound = $00000000
notice that the hi-order word refers to right channel and
lo-order word to left channel...
If use to set a mono soundcard, u specify the lo-order word
only.
WaveOutGetVolume retrieves the volume settings.
program Volume;
uses
Forms,
VolMain in 'VolMain.pas' {Main};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TMa in, Main);
Application.Run;
end.
-------------------------- -
unit VolMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, MMSystem, MPlayer;
type
TMain = class(TForm)
Button1: TButton;
Slide: TScrollBar;
Button2: TButton;
VolSet: TStaticText;
Label3: TLabel;
MPlay: TMediaPlayer;
Label2: TLabel;
ID: TStaticText;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SlideChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Main : TMain; // Form created
by Delphi
MMCode : MMResult; // Return value
used by MMSystem
Vol : DWord; // Volume setting
implementation
{$R *.DFM}
// Horizontal ScrollBar Change Event
procedure TMain.SlideChange(Sender: TObject);
begin
VolSet.Caption := IntToStr(Slide.Position); // Display
current volume
Vol := MakeLong(Slide.Position,Sl ide.Positi on); // Store in both
halves
MMCode := waveOutSetVolume(MPlay.Dev iceID, Vol); // Change volume
setting
end;
// Form OnCreate Event
procedure TMain.FormCreate(Sender: TObject);
begin
MPlay.FileName := 'SoundFil.WAV'; // Assign & Open
a file
MPlay.Open;
ID.Caption := IntToStr(MPlay.DeviceID); // Get Device ID
from MediaPlayer
MMCode := waveOutGetVolume(MPlay.Dev iceID, @Vol); // Get current
volume setting
Slide.Position := Vol And $0000FFFF; // Set the slider
to this setting
VolSet.Caption := IntToStr(Slide.Position); // Display
current volume
end;
// Play Button OnClick Event
procedure TMain.Button1Click(Sender: TObject);
begin
MPlay.Play; // Play the
current sound file
end;
// Exit Button Onclick
procedure TMain.Button2Click(Sender: TObject);
begin
MPlay.Close; // Close the
media player
Close; // Close the
application
end;
end.
OR of course, you could just use a Volumn Component. There are many of them on Delphi Super Page, or ww.Torry.net
Shane
The two key functions are waveOutSetVolume and waveOutGetVolume in
MMSystem. The trick is to get the Device ID for use with those
functions. This program uses the MediaPlayer component for that.
WaveOutSetVolume(hwo: Integer; dwVolume: Cardinal);
hwo is MediaPlayer1.DeviceId,
example: Right\/ | Left\/
dwVolume for Full L+R = $FFFFFFFF
dwVolume for Full L no R = $0000FFFF
dwVolume for Full R no L = $FFFF0000
dwVolume for no sound = $00000000
notice that the hi-order word refers to right channel and
lo-order word to left channel...
If use to set a mono soundcard, u specify the lo-order word
only.
WaveOutGetVolume retrieves the volume settings.
program Volume;
uses
Forms,
VolMain in 'VolMain.pas' {Main};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TMa
Application.Run;
end.
--------------------------
unit VolMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, MMSystem, MPlayer;
type
TMain = class(TForm)
Button1: TButton;
Slide: TScrollBar;
Button2: TButton;
VolSet: TStaticText;
Label3: TLabel;
MPlay: TMediaPlayer;
Label2: TLabel;
ID: TStaticText;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SlideChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Main : TMain; // Form created
by Delphi
MMCode : MMResult; // Return value
used by MMSystem
Vol : DWord; // Volume setting
implementation
{$R *.DFM}
// Horizontal ScrollBar Change Event
procedure TMain.SlideChange(Sender: TObject);
begin
VolSet.Caption := IntToStr(Slide.Position); // Display
current volume
Vol := MakeLong(Slide.Position,Sl
halves
MMCode := waveOutSetVolume(MPlay.Dev
setting
end;
// Form OnCreate Event
procedure TMain.FormCreate(Sender: TObject);
begin
MPlay.FileName := 'SoundFil.WAV'; // Assign & Open
a file
MPlay.Open;
ID.Caption := IntToStr(MPlay.DeviceID); // Get Device ID
from MediaPlayer
MMCode := waveOutGetVolume(MPlay.Dev
volume setting
Slide.Position := Vol And $0000FFFF; // Set the slider
to this setting
VolSet.Caption := IntToStr(Slide.Position); // Display
current volume
end;
// Play Button OnClick Event
procedure TMain.Button1Click(Sender:
begin
MPlay.Play; // Play the
current sound file
end;
// Exit Button Onclick
procedure TMain.Button2Click(Sender:
begin
MPlay.Close; // Close the
media player
Close; // Close the
application
end;
end.
OR of course, you could just use a Volumn Component. There are many of them on Delphi Super Page, or ww.Torry.net
Shane
ASKER
What am I missing here? Shouldn't this play the video with the sound off? (I'm running this no XP)
----------------
with MediaPlayer1 do begin
try
FileName := 'c:\test\test.mpg';
Open;
ID.Caption := IntToStr(MediaPlayer1.Devi
WaveOutSetVolume(MediaPlay
play;
except
showmessage('error');
end;
end;
ASKER
Whoops, typo.... "on XP" :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Shane