• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java sound: how to play a file?

 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean by "way too hard", but this doesn't look all that complicated.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, Thank you. Closing topic... Err...resolving it *clicks resolve*
John Price aka cc11rocks
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And that means to never ignore them but at least print their stack traces.
 
Greg Charles
Sheriff
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic