javax.sound.sampled.LineUnavailableException : Why am I getting this exception?
Asked Answered
N

2

6

When the following method is executed:

private void beep_player_1() {
    try {
        //clip_Player_2.close();
        clip_Player_1 = AudioSystem.getClip();
        ais = AudioSystem.getAudioInputStream(new File(Constants.Player1_Default_Tone)); // PATH FOR THE .WAV FILE
        clip_Player_1.open(ais);
        clip_Player_1.loop(0); // PLAY ONCE
    }catch(Exception exc) {
        System.out.println(exc);
     }
}

LineUnavailableException get thrown. What could be the reason for this?

javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 24 bit, stereo, 6 bytes/frame, little-endian not supported.
Naima answered 6/4, 2013 at 14:45 Comment(0)
A
3

What could be the reason for this ?

javax.sound.sampled.LineUnavailableException: line with format 
  PCM_SIGNED 44100.0 Hz, 
  24 bit, 
  stereo, 
  6 bytes/frame, 
  little-endian not supported.

I don't know about the rest, but most PCs I've encountered use 8 or 16 bit 'bit depth' while that uses 24 bits. It indicates a very finely nuanced recording quality. If 8 bit is 'phone quality' and 16 bit is 'CD quality', then 24 bit would be 'master recording quality'.

Argot answered 6/4, 2013 at 23:31 Comment(8)
You know if I change the sound clip,it works ! But I do not understand this.Naima
The previous file has a bit rate of 2116kbps and the new file has a bit rate of 1411kbps. Does it make any difference ?Naima
"if I change the sound clip,it works" Print the format (use AudioInputStream.getFormat()) of the working (changed) sound-clip.Argot
PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian : format for the working oneNaima
So, why doesn't it play the 24 bit format ? Though I converted the that file to 16 bit from 24Naima
It's just the way things are. PCs are set up to handle 16 bit sound typically, so Java Sound provides no support for 24 bit, only 8 and 16 bit.Argot
okay ! Thanks. I didn't know about this. But seeing the growing popularity of 24 bit encoding, I hope it starts supporting soon :)Naima
If someone is still interested in this: There are plenty of online wav-converters from x-Bit to 16-Bit .wav-filesIntercrop
G
0

This is a known issue, but it is on Windows only. Java does not recognize the ability of sound devices on Windows to play 24 bit data (or record 24 bit data). Java handles 24-bit on Linux and Mac well. I have seen other threads here and in other places on this, some started in 2012.

Not many people are pointing this issue out. I have only seen a couple of threads here and one on Oracle re this. I have not seen a workaround (other than convert sound data to 16 bit) and I have not seen any efforts to fix it.

Gnosticize answered 20/1, 2021 at 1:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.