954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to play Audio Clips

Other than the usual

AudioInputStream stream = AudioSystem.getAudioInputStream(ClassLoader.getSystemClassLoader().getResource("____.wav"));      
					DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat());      
					Clip clip = (Clip) AudioSystem.getLine(info);         
					 clip.open(stream);
					 clip.start();


Since the buffer limit is 2mb for an UNCOMPRESSED wav file so... it's pretty obvious how crappy that is... and that's about all I found on the net since the rest that are floating around don't work anymore(such as using sun's audioplayer, which is now restricted). Any ideas or nudges in the right direction? I'm not making a media player, just playing the clip in the background so I would most likely run this on a separate thread. Any ideas what method would be best for that? especially if I might put a wait()/notify() for it to end the clip prematurely if needed. Thanks in advance!

hanslim77
Newbie Poster
8 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

Go to this link and read the article on how to play audio in java. http://www.javaworld.com/javatips/jw-javatip24.html

Hope that fixed your problem. ( ;

DarkLightning7
Junior Poster in Training
71 posts since Jan 2011
Reputation Points: 15
Solved Threads: 7
 

already said... using that sun audio thing doesn't work anymore if I'm correct... Eclipse gives me the restricted codes error thing... also, working with clips is bad unless I can increase the buffer size, since it only accepts UNCOMPRESSED wav files up to 2mb(uncompressed meaning my 1:37 192kbps mp3 at 2.5mb turns into 22mb at 128kbps... had to make it run at 8kbps at 11000hz on mono just for it to work) so I don't think that's the best

hanslim77
Newbie Poster
8 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

Anyone at all who can help please? :(

hanslim77
Newbie Poster
8 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

there are different ways, you can also add a package that can play .mp3 's and use that :)

for instance the jmf (java media framework) or the framework used in JavaZoom .

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

I'll try looking up jmf, thanks.. though how do you install that into eclipse?

hanslim77
Newbie Poster
8 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

don't know, never used that one. I did however used the JavaZoom package, that's just a .jar file you need to add to your application, after which you just call the right methods

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: