我正在编写程序来循环java上的音频文件(BlueJ)按下按钮时连续不断。我的代码适用于小于1Mb的Wav Audio文件,但不适用于大于1mb的任何大小。我可以播放的文件大小是否有限制?如果是这样,我该如何解决这个问题呢?任何帮助都会很棒,谢谢。这是我的代码: -
import javax.swing.*;
import sun.audio.*;
import java.awt.event.*;
import java.io.*;
public class sound
{
public static void main(String args[])
{
JFrame frame = new JFrame();
frame.setSize(200,200);
JButton button = new JButton("Button name");
frame.add(button);
button.addActionListener(new AL());
frame.show(true);
}
public static class AL implements ActionListener
{
public final void actionPerformed(ActionEvent e)
{
music();
}
}
public static void music()
{
AudioPlayer MGP = AudioPlayer.player;
AudioStream BGM;
AudioData MD;
ContinuousAudioDataStream loop = null;
try
{
BGM= new AudioStream(new FileInputStream(file name));
MD = BGM.getData();
loop=new ContinuousAudioDataStream(MD);
}
catch(IOException error){}
MGP.start(loop);
}
}