本文介绍了在Java中播放Windows Media音频文件(.wma)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Java中读取.wma歌曲文件.我正在使用此代码.但是此代码是错误的.
(错误== javax.sound.sampled.UnsupportedAudioFileException:无法从输入文件获取音频输入流)
how to read .wma song file in java. I''m using this code. but this code is error.
(Error == javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file )
private void playAudio() {
try {
File soundFile =
new File("Track_1.wma");
audioInputStream = AudioSystem.getAudioInputStream(soundFile);
audioFormat = audioInputStream.getFormat();
System.out.println(audioFormat);
DataLine.Info dataLineInfo =
new DataLine.Info(
SourceDataLine.class,
audioFormat);
sourceDataLine =
(SourceDataLine) AudioSystem.getLine(
dataLineInfo);
new PlayThread().start();
} catch (Exception e) {
e.printStackTrace();
}
}
class PlayThread extends Thread {
byte tempBuffer[] = new byte[10000];
public void run() {
try {
sourceDataLine.open(audioFormat);
sourceDataLine.start();
int cnt;
while ((cnt = audioInputStream.read(
tempBuffer, 0, tempBuffer.length)) != -1
&& stopPlayback == false) {
if (cnt > 0) {
sourceDataLine.write(
tempBuffer, 0, cnt);
}
}
sourceDataLine.drain();
sourceDataLine.close();
} catch (Exception e) {
e.printStackTrace();
}
请帮帮我.
谢谢.
Please help me.
Thanks.
推荐答案
这篇关于在Java中播放Windows Media音频文件(.wma)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!