Solved

How to play a sound from the shell with java ?

Posted on 2004-03-30
9
215 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:digi_mind
  • 3
  • 2
  • 2
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10717860
Use Runtime.exec();
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 10717866
Process p = Runtime.getRuntime().exec(command);
0
 

Author Comment

by:digi_mind
ID: 10717982
It does not work

 Use Runtime.exec();
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10718023
Runtime.getRuntime().exec("play mysound.wav");
0
 
LVL 92

Expert Comment

by:objects
ID: 10718091
what command did you try?
Try using the full path to the executable and sound file.
0
 

Author Comment

by:digi_mind
ID: 10718421
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
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10718760
>> 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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Python Assistance 7 80
jdbc error in jsp application 20 44
JavaFX TableView not displaying correctly 3 16
Facing this issue for maven proxy setting 2 9
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question