我的代码有什么问题?它有关于 SUN API 的警告。它说,它可能会在未来的版本中删除。
import java.io.*;
import java.net.*;
import sun.audio.AudioData;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import sun.audio.ContinuousAudioDataStream;
AudioPlayer myBackgroundPlayer = AudioPlayer.player;
ContinuousAudioDataStream myLoop = null;
//use a try block in case the file doesn't exist.
try {
AudioStream myBackgroundMusic = new AudioStream(new FileInputStream("Audio/loop2.wav"));
AudioData myData = myBackgroundMusic.getData();
myLoop = new ContinuousAudioDataStream(myData);
}
catch(Exception error) {JOptionPane.showMessageDialog(null, "Invalid file!");}
//play background music.
myBackgroundPlayer.start(myLoop);
当我运行此代码时它说的无效文件..