I use TMediaPlayer and the following procedure:
procedure TForm1.PlayAudio(ResourceID: string);
var
ResStream: TResourceStream;
TmpFile: string;
begin
ResStream := TResourceStream.Create(HInstance, ResourceID, RT_RCDATA);
try
//TmpFile := TPath.Combine(TPath.GetTempPath, 'tmp.wav');
TmpFile :=(System.IOUtils.TPath.GetDocumentsPath + System.SysUtils.PathDelim + 'tmp.wav');
ResStream.Position := 0;
ResStream.SaveToFile(TmpFile);
MediaPlayer1.FileName := TmpFile;
MediaPlayer1.Play;
finally
ResStream.Free;
end;
end;
To play sounds from my resources like this: PlayAudio('Resource_1');
which are .wav and .mp3
It works fine on Windows but when I deploy it on Android it won't play any sounds, and I still can't find well explained way to play sounds on android from my resources. What is the best way to do so?
Thanks @RemyLebeau for pointing out that I need to find my path to resources using
TPath.Combine(TPath.GetDocumentsPath, 'filename') { Internal }
TPath.Combine(TPath.GetSharedDocumentsPath, 'filename') { External }
if Im deploying to android, but the files still couldn't run, and then I realized that I was using .mp3 and .wav. I converted them to .3gp and now sound works just fine on android.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.