尝试播放.wav文件时java中的音频流错误

时间:2014-01-12 21:49:14

标签: java audio wav

当我尝试在java中播放声音时,编译器会抛出一个错误,指出“java.io.IOException:无法从输入流创建音频流”

我尝试使用许多不同类型的wav进行测试,但似乎仍然不想工作。

package music;

import sun.audio.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.JButton;
import javax.swing.JFrame;

public class music {
static AudioPlayer amp = AudioPlayer.player;
static AudioStream strm;
static AudioData adata;
static ContinuousAudioDataStream loop = null;


@SuppressWarnings("deprecation")
public static void main(String[] args)
{
    JFrame frame = new JFrame();
    frame.setSize(200, 200);
    JButton button = new JButton("Test");
    frame.add(button);
    button.addActionListener(new AL());
    frame.show(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
public static class AL implements ActionListener{

    @Override
    public final void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        playmusic();
    }}


public static void playmusic()
{

    try {
        strm = new AudioStream(new FileInputStream("C:\\Users\\smashed\\Desktop\\GameaudioTest\\omnidirectionalgunsound.wav"));
        adata = strm.getData();
        loop = new ContinuousAudioDataStream(adata);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    amp.start(loop);


}

}

0 个答案:

没有答案