The wav files used in this program were created in GarageBand on the Mac. The wav files are included with the source code, so, feel free to use them. Calling sound files to play on Windows computers is quick and easy. Load MMSystem under Uses and use the command:


PlaySound(‘File Path’,0, SND_ASYNC);


The Mac requires a process to call afplay. afplay is bundled with Mac 10.5 or higher. There are directions on how to install afplay on older computers using Xcode.



http://mungbean.org/blog/?p=520



The Mac setup is as follows:


Load Process under Uses and create a procedure under public:


procedure PlaySound(SoundFile:String);



Then someplace under Implementation:


procedure NameOFForm.PlaySound(SoundFile:String);


var

  afsound:TProcess;


begin

  afsound := TProcess.Create(nil);

  afound.CommandLine := ‘afplay ‘ + SoundFile;

  afsound.Execute;

  afsound.Free;

end;


Wherever you want to play sound within your code add:


PlaySound(‘File Path’);




The code for the Quick Clock Quizzer can be download on the Tutorial 32 page



Video: Free Pascal Tutorial 28 - Sound and Music - Quick Clock Quizzer - Lazarus








Previous                   Next