Is there any way to play a sound alert/beep on Delphi XE5/Android platform?
What I'm trying to achieve is how to play system alert/beep sound like Windows application using Beep function or at least find the path of system's audio files so I can run specific audio file based on an event.
I ended up using resource files to play my custom audio file.
Steps:
Note: Make sure the media type is supported by TMediaPlayer otherwise it won't work.
Delphi Procedure:
procedure PlayAudio(ResourceID: string);
var
ResStream: TResourceStream;
TmpFile: string;
begin
ResStream := TResourceStream.Create(HInstance, ResourceID, RT_RCDATA);
try
TmpFile := TPath.Combine(TPath.GetTempPath, 'tmp.mp3');
ResStream.Position := 0;
ResStream.SaveToFile(TmpFile);
MediaPlayer1.FileName := TmpFile;
MediaPlayer1.Play;
finally
ResStream.Free;
end;
end;
Usage:
PlayAudio('Resource_1');
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