PLAYING SOUND WITHOUT JApplet

Hi there,

I'm a new member in Java Developer forums, I hope that I'll be an effective member..

for now I need help with java sound , multimedia

I'm developing a program that part of it is to play array of sounds (Not JApplet) I tried to use the function AudioClip(getClass().getResources("soundName.wav"); but it works only with JApplet

I want to play the sound without JApplet

I found that there is a package called javax.swing.sound.*;

but syntax error occured in my program.. that this package does not exist..

Please help me..

[585 byte] By [compumana] at [2007-10-3 11:53:40]
# 1
h?im having the same problem ill tried to play my sound files without an appletdo you know the solut齩n or thisthanks a lot
syasara at 2007-7-15 14:28:08 > top of Java-index,Security,Cryptography...
# 2
java.applet.AudioClip can be used outside of a JApplet. It worked for me in a stand-alone application.
rexyounga at 2007-7-15 14:28:09 > top of Java-index,Security,Cryptography...
# 3

Here is a sample. I run it in standalone

public class Music

{

public static void main(java.lang.String[] args)

{

java.applet.AudioClip sound = null;

try

{

String userdir= System.getProperties().getProperty("user.dir") ;

java.io.File myfile = new java.io.File("mymusic.mp3");

java.net.URI uri = myfile.toURI();

sound = java.applet.Applet.newAudioClip(uri.toURL());

sound.play();

}

catch (Exception io){/* on ne fait iren si cela ne marche pas*/ }

}

martinelligegea at 2007-7-15 14:28:09 > top of Java-index,Security,Cryptography...
# 4
This may be a stupid question but i'm pretty new at java and i was wondering if you set the "user.dir" to the directory of your music and the "mymusic.mp3" to the exact song you want.....
Timm017a at 2007-7-15 14:28:09 > top of Java-index,Security,Cryptography...
# 5
Try it and find out, you'll find the answer quicker than we can ever hand it to you.
Introvituma at 2007-7-15 14:28:09 > top of Java-index,Security,Cryptography...
# 6
i did try it out and i put my a message in this catch and it says that it runs successfully but nothing plays. i used "user.dir" for the folder my music's in and "mymusic.mp3" for the song title. so it may be quicker to just "hand it to me."thanks
Timm017a at 2007-7-15 14:28:09 > top of Java-index,Security,Cryptography...
# 7

I am also having the same problem. I couldn't get sound to work with the applet based one. I have the below code, it compiles and when you run the program it runs the length of the audio file but there is no sound? Is there something missing?

import sun.audio.*;//import the sun.audio package

import java.io.*;

public class sound{

public static void main (String args[])

{

try

{

InputStream in = new FileInputStream("cows2.au");

AudioStream as = new AudioStream(in);

AudioPlayer.player.start(as);

AudioPlayer.player.stop(as);

}

catch (Exception e)

{

System.out.println("Failed");

}

}

} //end class

Message was edited by:

Lisa_g

Lisa_ga at 2007-7-15 14:28:09 > top of Java-index,Security,Cryptography...
# 8
BUMP
Lisa_ga at 2007-7-15 14:28:09 > top of Java-index,Security,Cryptography...
# 9
java.applet.AudioClip now does not support MP3, you should try a .mid file or others supported!
polly_mana at 2007-7-15 14:28:09 > top of Java-index,Security,Cryptography...
# 10
illegal escape characterString userdir = System.getProperties()^
PaTa at 2007-7-15 14:28:09 > top of Java-index,Security,Cryptography...
# 11
Hi,Give the stop instruction in different function or set a time limit or set after finished playing the song.for now make it as a comment and try it will work and play sound.//AudioPlayer.player.stop(as);
Mskumara at 2007-7-15 14:28:09 > top of Java-index,Security,Cryptography...