Advertisement
BankUpload Join!

Friday, February 6, 2015

2.Delphi -Android Play Sound

Android Play Sound From Stream File
From Delphi IDE click on "Project". Then select "Resources and Images...". Choose your media file and set it as RCDATA. Remember your resource identifier. Note: Make sure the media type is supported by TMediaPlayer otherwise it won't work.
uses
System.IOUtils;

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;
PlayAudio('Resource_1');

 
Important Note: Most of my code into notepad deposited collected from different sources. For this reason, do not specify a majority in the source. Such is the case and you have a code that you know the source of the spell would be requested to notify the comments. Regards.

No comments:

Post a Comment