这是代码,就像标题说音乐在10秒后停止,我在vlc或其他程序中正常播放文件,它持续超过5分钟.
public void music(){
String bip = "src/data/fjordmusic.mp3";
Media hit = new Media(Paths.get(bip).toUri().toString());
MediaPlayer mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();
}
解决方法:
你的问题已经在这里被问到并回答了:
MediaPlayer stop playing after about 5 seconds
垃圾收集器似乎在完成该方法后对MediaPlayer实例进行了设置.将MediaPlayer的声明放在方法之上,它应该可以工作.
MediaPlayer mediaPlayer
public void music(){
String bip = "src/data/fjordmusic.mp3";
Media hit = new Media(Paths.get(bip).toUri().toString());
mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();
}
(我无法发表评论,所以我不得不写一个答案.)