本代码将讲解如何使用之前编写的音频播放器
注:目前播放器只可播放WAVE类型音频文件,后续将会开发更多类型与功能
请看下方代码
注:代码中的类 SoundPlayer 是前篇文章中讲解的内容,将其中代码创立为对应的类,并调用(例:import SoundPlayerTool.SoundPlayer)即可
SoundPlayer中代码对应文章:JAVA音频研究5
如:
import SoundPlayerTool.SoundPlayer;
public class MusicPlayer {
public static void main(String[]args) throws Exception {
SoundPlayer musicPlayer = new SoundPlayer();
musicPlayer.setSoundFilePath("C:\\Users\\17512\\Desktop\\bgm3.wav");
musicPlayer.start(true);//开始播放
//musicPlayer.pause();暂停播放
//musicPlayer.continues();继续播放
//musicPlayer.stop();停止播放
//musicPlayer.setSoundFilePath("C:\\Users\\17512\\Desktop\\bgm2.wav");//更换音乐
//musicPlayer.start(true);//开始播放(切歌)
}
}