-1

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?

5
  • You can copy the wavs to a RAM filesystem like tmpfs.
    – stark
    May 26 at 14:04
  • @stark does it mean that I need after the start of my videogame copy all the audio files (direct from java) in the /tmp directory and when I need the sounds to be played I load this files not from the directory with the game but from the \tmp? May 26 at 15:07
  • Correct. That saves the disk access if the files are not in cache.
    – stark
    May 26 at 15:23
  • Start here: Java Sound Programmer's Guide May 26 at 18:25
  • @Jim Garrison bad idea, I don't need to play sound direct from Java May 27 at 16:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.