Solved

How to play a sound from the shell with java ?

Posted on 2004-03-30
9
213 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
where is session ID cache stored 1 40
for i loop in grovy 1 32
Java and GPO 11 47
Error with Java/Cache JDBC Classpath 2 20
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now