I write a java application that also must play audio files. I can not use MediaPlayer class and any other classes which control the playing through the JVM. That is why I want to launch sound files using terminal commands which will be called from the java code. I prefer to use this code
Process proc = Runtime.getRuntime().exec(command);
where command is the String-representation of the command must be called in the terminal. I have installed Sox using:
sudo apt install sox
and now I can play the sounds using the next terminal command:
play music.mp3
it works but I don’t know how can I manage three files which can be played at the same time. My java application is a java videogame for an arcade cabinet that must run on a Raspberry Pi 16 hours at the day. It must play one soundtrack (one long WAV-file ), that must be looped and two short sound files (shot-sound and explosion-sound). What will be with the memory and the performance of my game if I will simple run
Process proc = Runtime.getRuntime().exec("play music.mp3");
every time I need to play the shot? Will the Linux load in the memory the new copy of the sound file again every time? Will the Linux dispose the uploaded sound from the memory after it played and I need to load the sound every time again? Maybe I need to save all three objects of the Process-class and call in every of this objects command that can play the sound again without the new uploading? Maybe there are another terminal commands which I should use or another utilities?