Sitemap

Amicuk Programming Answers

Why doesnt a sound play when I change the path?

2015-10-11   Views:0

Advertisement

Hi. I am trying to play a background sound in my program and so far, after searching and reading lots of posts I finally have a "TaDa" sound playing once when the program starts. But what I want is a sound to be looped everytime I start a progra

Hi. I am trying to play a background sound in my program and so far, after searching and reading lots of posts I finally have a "TaDa" sound playing once when the program starts. But what I want is a sound to be looped everytime I start a program. That sound will be in the same folder as the program.
This is the code that I put in public static void main() to play the sound:
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
java_testt b = new java_test();
b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.startApp();
private void startApp()
{playStartupSound();}
private void endApp() {System.exit(0);}
private void playStartupSound() {
Runnable soundPlayer = new Runnable() {
public void run() {
try {                                                                                    
File tadaSound = new File(System.getenv("windir") + "/" + //This is the windows tada sound. All I want is
"media/tada.wav"); //to change the path to another sound
AudioInputStream audioInputStream = AudioSystem
.getAudioInputStream(new FileInputStream(tadaSound));
AudioFormat audioFormat = audioInputStream
.getFormat();
DataLine.Info dataLineInfo = new DataLine.Info(
Clip.class, audioFormat);
Clip clip = (Clip) AudioSystem
.getLine(dataLineInfo);
clip.open(audioInputStream);
clip.start();
} catch (Exception e) {
e.printStackTrace();
Thread soundPlayingThread = new Thread(soundPlayer);
soundPlayingThread.start();
Does anyone know how to choose another sound in the same folder as java_test and make it work with this code because when I change the ath it doesnt run.
Thanks.

The replay answer
Advertisement
Please put your code between the code tags. It's much better readable then.
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
java_testt b = new java_test();
b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.startApp();
private void startApp()
{playStartupSound();}
private void endApp() {System.exit(0);}
private void playStartupSound() {
Runnable soundPlayer = new Runnable() {
public void run() {
try {
File tadaSound = new File(System.getenv("windir") "/" //This is the windows tada sound. All I want is
"media/tada.wav"); //to change the path to another sound
AudioInputStream audioInputStream = AudioSystem
.getAudioInputStream(new FileInputStream(tadaSound));
AudioFormat audioFormat = audioInputStream
.getFormat();
DataLine.Info dataLineInfo = new DataLine.Info(
Clip.class, audioFormat);
Clip clip = (Clip) AudioSystem
.getLine(dataLineInfo);
clip.open(audioInputStream);
clip.start();
} catch (Exception e) {
e.printStackTrace();
Thread soundPlayingThread = new Thread(soundPlayer);
soundPlayingThread.start();
}

Go to See the other 15 answers

Why doesnt a sound play when I change the path?

Category:DefaultRelease time:2015-10-11Views:130

Hi. I am trying to play a background sound in my program and so far, after searching and reading lots of posts I finally have a "TaDa" sound playing once when the program starts. But what I want is a sound to be looped everytime I start a progra[More]

Why doesnt the sound play when i mirror my laptop to my apple tv play?

Category:DefaultRelease time:-0001-11-30Views:130

why doesnt the sound play off my speakers when i mirror my laptop to my apple tv?Answers can only be as helpful as the details provided.  And none were given here.  It is likely an issue with the device settings, and or a conflict with the type of au[More]

HT1688 My Iphone 4 doesnt record sound or the speakerphone works after lastest update

Category:DefaultRelease time:-0001-11-30Views:130

My Iphone 4 doesnt record video sound or the Speakerphone is working any news on that?Hi Gus52, Welcome to the Support Communities! The article below may be able to help you with this. Click on the link to see more details and screenshots.  iPhone: M[More]

Iphone 4 doesnt play sound through speakers

Category:DefaultRelease time:-0001-11-30Views:130

My IPhone 4 doesnt play any sound when I'm playing a game or any app but when i play music it works fine. How do i fix this?Hello there, B1011. The following Knowledge Base article offers up some great basic steps for troubleshooting issues with appl[More]

My ipod doesnt play sound on Videos

Category:DefaultRelease time:-0001-11-30Views:130

I have recently purchased the 80GB Ipod video,and I uploaded many videos but it doesnt play the sound.Could any one help me on this?Quicktime or Quicktime Pro (which iTunes uses) don't convert "muxed" ( muxed means multiplexed where the audio an[More]

Why my facebook notification doesnt have sound

Category:DefaultRelease time:-0001-11-30Views:130

Why my facebook notification doesnt have a sound? I've tried to restart, reinstall my facebook, update new version, set the sound on notification But it wont workIf the videos are multiplexed MPEG files then the audio and the video are muxed onto the[More]

Ipod nano 3rd gen. doesnt have sound during videos

Category:DefaultRelease time:-0001-11-30Views:130

i upload videos into itunes and they play fine, with sound. after converting to ipod format the sound is lost. the video is fine, but the sound is either absent or loud crackling. help please!Welcome to Apple Discussions! If the sound is absent, it i[More]

Videos in my ipod doesnt have sounds...

Category:DefaultRelease time:-0001-11-30Views:130

my videos have no sounds... why is this?? windows   Windows XP  my videos have no sounds... why is this?? windows   Windows XP   As the person before me said, you will need a third party converter for your video. I had the same problem when I got my[More]

Importing vob file doesnt have sound

Category:DefaultRelease time:-0001-11-30Views:130

i have the mpeg 2 converter and imported one vob file without a problem but imported a second and it went into quicktime fine but had no sound. why is thatI've the same problem with my Sony N1-digital camera, quicktime can't convert it for iMovie (no[More]

Email doesnt make sound when I get new mail

Category:DefaultRelease time:-0001-11-30Views:130

iphone 4s ....  everything else makes a sound but when new emails come in, I am not notified by a sound.  I have updated to OS6 but nothing seems to help.Have you looked at settings/sounds to seewhat sound you have chosen for new email?Read other 2 a[More]

My new 110hs elf doesnt record sound in movie mode

Category:DefaultRelease time:-0001-11-30Views:130

no volume on record movie modeBrucer, Do you not hear sound only when playing video back on your camera, or is there also no sound when you play video back on your computer? If this is a time sensitive-matter, additional support options are available[More]

Hot
I am using a lap top, just reinstalled everything, and now have Firefox 9.1 and am being told it is not compatible with my antivirus, Trend Micro Titanium. I am running Windows 7.See: * http://community.trendmicro.com/t5/Home-and-Home-Office-Forum/Re [More]
Upon upgrading the SPA122 to firmware 1.2.1 I found that outbound DTMF tones were no longer being seen properly by remote systems.  Using the device web interface and changing the Line 1 "DTMF Tx Method" to "InBand" (using "Submit [More]
"There do not appear to be any chapters in your table of contents. This suggests that you need to properly set chapter divisions in your document." Is what I keep getting everytime I try to convert my Microsoft Office file to an ePub. I have mad [More]
the scroll pad isnt scrolling around the main menu nor is the letter 's' working at all...you know how many words use the letter 's'??? anyways, any ideas what i should do? i done a battery pull, resetting the phone, updating it.....so help? please?K [More]
Windows Vista Business, 32 bit, W/Microsoft Wireless Laser mouse 5000 v1.0. Mouse scoll wheel will not work w/iTunes 7.6. No problems w/previous editions of iTunes. Downloaded and installed full copy of iTunes 7.6 for Vista (not 64 bit) and DID NOT c [More]
Help please? I am working in Illustrator CS4, and finished a 2-sided mailer/postcard for a client in cmyk. After emailing the final PDF to the client, the client responded back to me with their print provider's request for- "native file, with black a [More]
Hi folks, I using a ALV FM (K_KKB_FIELDCAT_MERGE)to display the data using.In 4.6 version the  date format used to display in MM/DD/YYY format whereas after the upgrade to ECC 6.0 version the date format is know dispalying in Sap std format YYYYMMMDD [More]
Why did my pdf not covert correctly to excel.  It says the extension is not correct.  I paid for this to do this correctly and I am pushed for time.  Please helpHi Debbie, I apologize for the inconvenience with your ExportPDF subscription. Are you st [More]
I am in Graduate School at Towson University. My project for school deals with implementing a Database Server for an existing system to get and set information in a database. The application uses Java RMI for the Client to access information on the S [More]
I want to save the data from the DAQ - Card just in case a pre-defined event (measured Value out of tolerance) occured. In that case, I want to have a File with Data 1 min before the event und 1 Minute after the event. I tried to find examples, but I [More]