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 ?
To play an audio file, click File, select Open, and browse to the location of the file. Or, you can drag the file to the RealPlayer window. You can also double-click the file to start playing the file immediately. However, if the audio file is associated with a different program, it may not open in RealPlayer.
Since WAV is quite a popular format, almost all devices today support it using built-in media players. On Windows, the Windows Media Player is capable of playing WAV files. On MacOS, iTunes or QuickTime can play WAV files. On Linux, your basic ALSA system can play these files.
The Windows Media Player can run from the command line or a batch file to play sound files. To ensure audio files are played using this application, you need to include the "wmplayer" after the start command.
Windows and Mac are both capable of opening WAV files. For Windows, if you double-click a WAV file, it will open using Windows Media Player. For Mac, if you double-click a WAV, it will open using iTunes or Quicktime. If you're on a system without these programs installed, then consider third-party software.
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;
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With