Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sound vs. no sound

Posted on 2004-04-09
7
Medium Priority
?
181 Views
Last Modified: 2012-05-04
If I'm playing a video with the mediaplayers, how do I turn the sound off?..... and back on?  (D5)

          Thanks
0
Comment
Question by:jexd99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10794758
WHat are you using to play the Video with (TMediaPlayer)?

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10794907
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(TMain, 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,Slide.Position);    // Store in both
halves
  MMCode := waveOutSetVolume(MPlay.DeviceID, 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.DeviceID, @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
0
 

Author Comment

by:jexd99
ID: 10795301

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.DeviceID);  
               WaveOutSetVolume(MediaPlayer1.DeviceID,$00000000);
               play;
             except
                showmessage('error');
             end;
           end;
0
 

Author Comment

by:jexd99
ID: 10795305
Whoops, typo.... "on XP"   :)
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13284879
PAQed with points refunded (125)

modulo
Community Support Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question