• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Java sound: how to play a file?

 
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, Thank you. Closing topic... Err...resolving it *clicks resolve*
John Price aka cc11rocks
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And that means to never ignore them but at least print their stack traces.
 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic