0
我正在嘗試將音頻播放器添加到我的應用程序。下面是從類來處理音頻播放代碼:BigClip不會播放.wav文件
package me.pogostick29.audiorpg.audio;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
public class AudioPlayer {
private AudioPlayer() { }
private static AudioPlayer instance = new AudioPlayer();
public static AudioPlayer getInstance() {
return instance;
}
private static ArrayList<BigClip> clips = new ArrayList<BigClip>();
private BigClip get(String name) {
for (BigClip clip : clips) {
if (clip.getName().equalsIgnoreCase(name)) return clip;
}
return null;
}
public void play(File file) {
try {
AudioInputStream audioIn = AudioSystem.getAudioInputStream(file);
BigClip clip = get(file.getName());
if (clip == null) {
BigClip newClip = new BigClip(file.getName());
clips.add(newClip);
clip = newClip;
}
clip.open(audioIn);
clip.start();
}
catch (Exception e) { e.printStackTrace(); }
}
}
然而,當我嘗試使用
AudioPlayer.getInstance().play(new File("audio/people/blacksmith/blacksmith01a_new.wav"));
運行它,我得到以下堆棧跟蹤:
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1170)
at me.pogostick29.audiorpg.audio.AudioPlayer.play(AudioPlayer.java:38)
at me.pogostick29.audiorpg.person.people.Blacksmith.playDialogue(Blacksmith.java:12)
at me.pogostick29.audiorpg.AudioRPG.main(AudioRPG.java:33)
以下是我用Audition導出文件時使用的格式:http://icap.me/i/AkRHDOFsCW.png
感謝您的幫助!
執行此代碼並報告結果。 'File f = new File(「audio/people/blacksmith/blacksmith01a_new.wav」); System.out.println(「File:」+ f.exists());' – 2013-04-10 00:13:55