EDIT: My initial test was done with Berlin while OP is using Tokyo. The results below hold true for Berlin. Please see further down for Tokyo.
I was curious as to why the code in the FMXExpress link you provided did not work since I use very similar code in my multi-platform audio class. So I decided to download the code and give it a try.
The demo app looks for 3 specific files ding1.wav, ding2.wav and ding3.wav; on Windows it looks for the files in the documents folder and on Android it expects the files in assetsinternal
For Windows I had to copy some audio files I had to the documents folder and rename them accordingly. The app worked fine as you reported. (Windows 10 Version 1709).
For Android I first took a look at the project's deployment settings. The 3x audio files are listed but the local path is blank. I just unchecked the existing entries and re-added them from my documents folder and set the remote path for each to assetsinternal. Compiled the app directly on a device I had connected and it worked fine. Android SDK 24.3.3 32-bit, LG-V522 G-Pad III running Android 7.0
EDIT - DESCRIPTION OF PROBLEM WITH TOKYO:
The OP is correct; the linked sample code does not work when compiled with Tokyo 10.2.3
Simple debugging showed that the callback TOnSpoolLoadCallBack.onLoadComplete
is never called which is required to set the global GLoaded
to True
. The effect is that the application loops indefinitely in the following code:
TGameAudioManager.AddSound
while not GLoaded do
begin
Sleep(10);
Application.ProcessMessages;
end;
To make the code work, (this is a hack) add a counter that limits the number of time the loop can run. Something like this...
procedure TGameAudioManager.AddSound(...)
const
MaxWaitLoop = 10;
var
...
loopCount : integer;
Begin
...
loopCount := 0;
while not GLoaded AND (loopCount < MaxWaitLoop) do
begin
inc(loopCount);
Sleep(10);
Application.ProcessMessages;
end;
...
With some logic to prevent indefinite looping, the application now works and audio is heard on the Android device.
Notes:
- You now need to figure out why the callback does not work in Tokyo. After a quick check and comparison with Berlin it wasn't obvious to me.
- You should not use this code in production.
Application.ProcessMessages
almost always points to a bad
implementation. Instead, the callback should bubble up to your main application where you can, for example, enable UI elements
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…