Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AppmethodCode SnippetDelphiFiremonkeyOSXWindows

Code Snippet To Play Sounds With Delphi XE7 Firemonkey On Windows and Mac OSX

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi XE7 Firemonkey Play Sound Windows Mac OSX | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSDeveloper CHackbart has a play sound code snippet for Firemonkey over on one of the Delphi forums. The posts are all in German but you can run it through a translator easily enough. The code snippet was written for one of the earlierĀ versions of Delphi but I tested it out in Delphi XE7 Firemonkey and it plays sounds on both Windows and Mac OSX. On Mac OSX it uses the NSSound object (as TNSSound) and on Windows it uses the PlaySound Win32 API call. There are other ways to call NSSound but this way worked on a very recent Mac OSX version. It should also work for you in Appmethod. If you are looking to play sounds on Android and IOS as well you should check out the TGameAudioManager component. Here is the code snippet:
uses
{$IFDEF MACOS}
MacAPI.CoreServices, MacAPI.Foundation, MacAPI.AppKit
{$ELSE}
Windows, MMSystem
{$ENDIF};
...
procedure TSound.Play(FileName: string);
begin
{$IFDEF MACOS}
TNSSound.Wrap(TNSSound.Alloc.initWithContentsOfFile(NSSTR(FileName),
true)).play;
{$ELSE}
PlaySound(PChar(FileName), 0, SND_ASYNC);
{$ENDIF}
end;

 
Check out the full forum post over on DelphiPraxis.net or just use the code snippet above.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts
DelphiFiremonkeyShowcaseUtilityWindows

Unleashing Creativity With Song Writer AI: A Deep Dive

DelphiFiremonkeyShowcaseWindows

How To Build Stable Diffusion Text To Image Prompts

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

DelphiIDEShowcaseWindows

Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores

Sign up for our Newsletter and
stay informed

1 Comment

Leave a Reply