Jlouro
Jlouro

Reputation: 4545

How can I play sound file (mp3,wav,etc) directly with no associated application?

I need also to be able to control its volume. Also, how do I control system sound volume, to detect low volume, or mute states ?

Upvotes: 6

Views: 10992

Answers (5)

Alister
Alister

Reputation: 6837

Have a look at this article: Your first MP3 Delphi player. It uses TMediaPlayer to be able to play mp3 files. Not exactly what you want, but a very good starting point.

Upvotes: 1

fred
fred

Reputation:

Just use MM apis (tons of samples on MSDN and google)

Upvotes: 0

Bruce McGee
Bruce McGee

Reputation: 15334

If this is for non-commercial use, the BASS libraries are free and give you the control you're looking for.

There are free video tutorials on 3DBuzz, one of which is creating your own MP3 player. They're in the Video Category list on the front page.

Upvotes: 2

Martijn
Martijn

Reputation: 13622

Use Shoban's link for how to play sound.

Here's how to control the sound volume for devices:

uses MMSystem;

type
   TVolumeRec = record
     case Integer of
       0: (LongVolume: Longint) ;
       1: (LeftVolume, RightVolume : Word) ;
     end;

const DeviceIndex=5
       {0:Wave
        1:MIDI
        2:CDAudio
        3:Line-In
        4:Microphone
        5:Master
        6:PC-loudspeaker}

procedure SetVolume(aVolume:Byte) ;
var 
  Vol: TVolumeRec;
begin
   Vol.LeftVolume := aVolume shl 8;
   Vol.RightVolume:= Vol.LeftVolume;
   auxSetVolume(UINT(DeviceIndex), Vol.LongVolume) ;
end;

function GetVolume:Cardinal;
var 
  Vol: TVolumeRec;
begin
   AuxGetVolume(UINT(DeviceIndex),@Vol.LongVolume) ;
   Result:=(Vol.LeftVolume + Vol.RightVolume) shr 9;
end;

Upvotes: 2

RED SOFT ADAIR
RED SOFT ADAIR

Reputation: 12218

char *mp3FilePath    = ...   ;
char *workingDirPath = ...   ;
ShellExecute(hwnd, "open", mp3FilePath, NULL, workingDirPath, SW_SHOWNORMAL);

Upvotes: -3

Related Questions