Java 无法播放JFlac创建的wav文件
我正在创建java音频播放器。我的目标文件是flac文件,JFlac库将其转换为wav文件。我遇到的问题是,当我尝试播放这首歌时,通过我的程序是一个例外。 例外情况具体如下:Java 无法播放JFlac创建的wav文件,java,audio,wav,bitrate,flac,Java,Audio,Wav,Bitrate,Flac,我正在创建java音频播放器。我的目标文件是flac文件,JFlac库将其转换为wav文件。我遇到的问题是,当我尝试播放这首歌时,通过我的程序是一个例外。 例外情况具体如下: java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 24 bit, stereo, 6 bytes/frame, little-endia
java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 24 bit, stereo, 6 bytes/frame, little-endian is supported.
但是,当我使用vlc播放器降低歌曲的质量时,比如降低其比特率值,我就可以毫无问题地播放歌曲。
但是我不能播放原始wav文件。
有没有办法降低java中wav文件的质量,或者我可以做些什么来播放这首歌
这是播放wav歌曲的地方:
public void playSound(String filename){
String strFilename = filename;
try {
soundFile = new File(strFilename);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
try {
audioStream = AudioSystem.getAudioInputStream(soundFile);
} catch (Exception e){
e.printStackTrace();
System.exit(1);
}
audioFormat = audioStream.getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
try {
//line where i am getting exception
**sourceLine = (SourceDataLine) AudioSystem.getLine(info);**
sourceLine.open(audioFormat);
} catch (LineUnavailableException e) {
e.printStackTrace();
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
sourceLine.start();
int nBytesRead = 0;
byte[] abData = new byte[BUFFER_SIZE];
while (nBytesRead != -1) {
try {
nBytesRead = audioStream.read(abData, 0, abData.length);
} catch (IOException e) {
e.printStackTrace();
}
if (nBytesRead >= 0) {
@SuppressWarnings("unused")
int nBytesWritten = sourceLine.write(abData, 0, nBytesRead);
}
}
sourceLine.drain();
sourceLine.close();
}
解码器功能:
public void decode(String inFileName, String outFileName) throws IOException {
System.out.println("Decode [" + inFileName + "][" + outFileName + "]");
FileInputStream is = null;
FileOutputStream os = null;
try {
is = new FileInputStream(inFileName);
os = new FileOutputStream(outFileName);
wav = new WavWriter(os);
FLACDecoder decoder = new FLACDecoder(is);
decoder.addPCMProcessor(this);
decoder.decode();
} finally {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
}
}
请帮忙。有人在吗!谁能帮我?或者任何建议,有人在吗!谁能帮我?或任何建议。