所以我遇到类似于java.io.IOException: mark/reset not supported的问题。java.io.IOException:标记/重置不支持(静态)
如何我希望它的工作:
- 使程序打开一个弹出按钮,说:“点击这里给我玩”
- 一旦用光标点击将扮演2MB_sound.wav(是其在2MB大小)永远
什么问题是:
不知怎的,我写代码调用backgroundPlayer完全工作正常,在桌面上的一个在我的单谱曲,但不是我的笔记本电脑。在我的笔记本电脑上运行代码时,弹出按钮可以正常工作,但是当我点击它时,它会给出错误“java.io.IOException:mark/reset not supported”。
我做了什么,试图解决这一问题,但失败了(从链接的回答以上):
InputStream audioSrc = getClass().getResourceAsStream("2MB_sound.wav");
InputStream bufferedIn = new BufferedInputStream(audioSrc);
AudioInputStream audioStream = AudioSystem.getAudioInputStream(bufferedIn);
我试图并称正是因为以上(有关进口)的代码,但它给了我一个不同的错误说:“不能从类型Object中对非静态方法getClass()进行静态引用”。所以现在我卡住了,回到我原来的代码,如下所示。
请帮我解决我的问题。
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JButton;
import javax.swing.JFrame;
public class backgroundPlayer {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(200,200);
JButton button = new JButton("Click me to play");
frame.add(button);
button.addActionListener(new AL());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static class AL implements ActionListener {
public final void actionPerformed (ActionEvent e) {
music();
}
}
public static void music() {
try {
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new FileInputStream("85046_newgrounds_parago.wav"));
clip.open(inputStream);
clip.loop(Clip.LOOP_CONTINUOUSLY);
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
}
}
}
它也发布在这里:https://论坛。 oracle.com/forums/thread.jspa?threadID=2289395&tstart=0 – 2012-02-17 07:04:43