How to play a sound from the shell with java ?

Simple... I am using Linux and Java.

In C++ I can make a program that calls a system function and allows me to play a sound from the shell. The call to the system function is:

System("play mysound.wav");

Is it there any way to do the same thing with Java... so I could call the same "play" function from the shell and the sound will be played ?

If there is some class I need to include, please tell me and tell me how.

Do not send me to complicated plages or give me some complicated code... I guess it should be simple.
digi_mindAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
Process p = Runtime.getRuntime().exec(command);
0
 
objectsCommented:
Use Runtime.exec();
0
 
digi_mindAuthor Commented:
It does not work

 Use Runtime.exec();
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Tommy BraasCommented:
Runtime.getRuntime().exec("play mysound.wav");
0
 
objectsCommented:
what command did you try?
Try using the full path to the executable and sound file.
0
 
digi_mindAuthor Commented:
Runtime.getRuntime().exec("play mysound.wav");

That command does not work... I have another one now which is more complicated, but works.

Runtime sound = Runtime.getRuntime();
sound.exec("play alarm.wav");

I share the code with you.
0
 
Tommy BraasCommented:
>> Runtime sound = Runtime.getRuntime();
>> sound.exec("play alarm.wav");

Is functionally the same as:

>> Runtime.getRuntime().exec("play alarm.wav");

That is what we suggested, except that you're using "play alarm.wav". We merely based our responses on what you had provided in your question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.