Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Java sound: how to play a file?

 
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
 
Rancher
Posts: 43011
76
  • 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
 
Sheriff
Posts: 21775
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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: 43011
76
  • 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
Posts: 21775
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
Sheriff
Posts: 3034
12
Mac IntelliJ IDE Python VI Editor Java
  • 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
Boost this thread!