Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 759
Jlouro Avatar asked Jul 17 '09 09:07

Jlouro


People also ask

How do I play an audio file?

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.

How can I listen to WAV files?

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.

Can CMD play sounds?

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.

How do I play WAV files on Windows?

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.


3 Answers

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;
like image 64
Martijn Avatar answered Oct 12 '22 01:10

Martijn


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.

like image 22
Bruce McGee Avatar answered Oct 12 '22 02:10

Bruce McGee


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.

like image 39
Alister Avatar answered Oct 12 '22 03:10

Alister