0

Similiar to AWTs java.awt.Image one can store and render an Image like:

Image img = ImageIO.read ("myImgFile");
...
g.drawImage (img, x, y, null);

The most straight forward approach for sound is to use the Clip like:

AudioStream snd = new AudioStream(new FileInputStream("mySndFile"));
...
clip = AudioSystem.getClip();
snd.play();

However, this does not work for .mp3 files, there are numerous questions (with answers) with the aid of 3rd party libraries. That is however unwanted if possible without.

Is it impossible?

Outdated 1, External Solution

Outdated 2, Non Standard? as per Access restriction: The type 'Media' is not API (restriction on required library 'C:\Program Files\Java\jre1.8.0_31\lib\ext\jfxrt.jar')

Community
  • 1
  • 1
Emz
  • 1,280
  • 1
  • 14
  • 29
  • 1
    Don't use awt. We're not living in the dark ages anymore. No, the way you propose it, mp3 is not supported. If I'm not mistaken, JavaFX does come with support, but never tried it. – Stultuske Dec 22 '15 at 08:11
  • 1
    I am building a wrapper around AWT, I am not even remotely interested in the layout managers or the gui elements of Swing. – Emz Dec 22 '15 at 08:13
  • 1
    in awt, mp3 is not supported. so "building around it" won't help you. If you don't want to go for JavaFX, JLayer is a quite easy-to-work-with and reliable library to play mp3 files – Stultuske Dec 22 '15 at 08:15
  • 1
    Java's audio library has very limited support for MP3 (from memory), but, like ImageIO, it supports pluggable extensions, JavaLoop's JLayer SPI been one – MadProgrammer Dec 22 '15 at 08:18
  • off-topic: Do you ever sleep @MadProgrammer ? on-topic again: *Last Update : 11/2010*, again with what seems to be a discarded and outdated resources? – Emz Dec 22 '15 at 08:21
  • If you can find a better one let me know, I've used it (a little in the past) and it worked okay for me. And no, I don't sleep, I have 3.5 year old that keeps me on my toes, so the only time I get to do any "development" (for myself) is when they are asleep :P – MadProgrammer Dec 22 '15 at 08:51

0 Answers0