第二个音频剪辑不播放。
好吧,具体来说,为什么这里的代码似乎不想播放第二个音频文件:
public static void main(String[] args) {
//Plays first file for a few seconds
playMusic(new File("C:\\sample.wav"));
wait(5.0);
System.out.print("...");
//Second file that doesn't want to play:
playMusic(new File("C:\\sample2.wav"));
}
public static void playMusic(File Stream) {
AudioInputStream AIS
= AudioSystem.getAudioInputStream(Stream);
Clip music = AudioSystem.getClip();
music.open(AIS);
music.start();
}
我想我必须忽略某些东西(例如 music.close()、AIS.close()),但这些特定的示例不好像没有什么效果。有什么想法吗?
Well, specifically, why this code here doesn't seem to want to play the second audio file:
public static void main(String[] args) {
//Plays first file for a few seconds
playMusic(new File("C:\\sample.wav"));
wait(5.0);
System.out.print("...");
//Second file that doesn't want to play:
playMusic(new File("C:\\sample2.wav"));
}
public static void playMusic(File Stream) {
AudioInputStream AIS
= AudioSystem.getAudioInputStream(Stream);
Clip music = AudioSystem.getClip();
music.open(AIS);
music.start();
}
I figure I have to dismiss something or other (e.g. music.close(), AIS.close()), but these particular examples don't seem to have any effect. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的应用程序是否有可能在音频剪辑播放完毕之前终止?您可能会发现这个这样的答案很有帮助。
Is it possible your application terminates before your audio clip has finished playing? You may find this SO answer helpful.