File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Java sound: how to play a file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Java sound: how to play a file?" Watch "Java sound: how to play a file?" New topic
Author

Java sound: how to play a file?

john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

How do I play a file? I converted an mp3 file to wav so I could use it with Java. I looked at some Java sound tutorials and they seemed way too hard. The ones that I found were good/easy were for applets... Could anyone give me a working example?
Thanks,
cc11rocks aka John Price


“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41497
    
  53
Not sure what you mean by "way too hard", but this doesn't look all that complicated.


Ping & DNS - my free Android networking tools app
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495


Warnings:

How to get rid of the warnings?
I've already tried:

Which gave me no errors, but still the same 7 warnings.
Thanks,
John Price aka cc11rocks
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

From the link, what exactly should this line be:

My code is not supposed to be streaming from the internet. It is a local file...
Thanks,
John Price aka cc11rocks
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

I found another one online. I had to modify it because it was missing the Exception catching and the try clause. Anyway, here is what worked. Is this the way it is supposed to be?

Thanks,
cc11rocks aka John Price
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

john price wrote:
Warnings:

How to get rid of the warnings?
I've already tried:

Which gave me no errors, but still the same 7 warnings.
Thanks,
John Price aka cc11rocks

You should never ignore these warnings. All classes in packages that start with sunw, sun or com.sun can change or be removed with any new release of Java. That's why they are undocumented. Using them may cause your programs to break when a new JRE / JDK is installed.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Okay, Thank you. Closing topic... Err...resolving it *clicks resolve*
John Price aka cc11rocks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41497
    
  53
john price wrote:Is this the way it is supposed to be?

It really goes without saying, but since you explicitly asked: you need to handle the exceptions in a meaningful way.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

And that means to never ignore them but at least print their stack traces.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2848
    
  11

OK, so the resolution is don't use sun.audio.AudioPlayer to play sounds; use javax.sound.sampled.AudioSystem, right? That's good to know!

Also, don't ignore warnings and don't swallow exceptions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java sound: how to play a file?