java audiostream 用不了_Java audiostream平台独立

我有以下方法来播放音频剪辑:

public static synchronized void playSound(final String path) {

new Thread(new Runnable() {

// The wrapper thread is unnecessary, unless it blocks on the

// Clip finishing; see comments.

public void run() {

try {

Clip clip = AudioSystem.getClip();

AudioInputStream inputStream = AudioSystem.getAudioInputStream(

this.getClass().getClassLoader().getResourceAsStream(path));

clip.open(inputStream);

clip.loop(Clip.LOOP_CONTINUOUSLY);

while (runThread) {

Thread.sleep(5000);

}

clip.stop();

}

catch (Exception e) {

System.err.println("Audio clip error: "+e.getMessage());

e.printStackTrace();

}

}

}).start();

}当我在Windows 7桌面平台(联想)上运行它时,它按预期工作。但是,在Windows 7笔记本电脑(Acer)上运行时,出现以下异常:

java.lang.NullPointerException

at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)

at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)

at StokerMonitor.Alerts$1.run(Alerts.java:62)

at java.lang.Thread.run(Unknown Source)第62行是'AudioInputStream'语句。我不知道两个平台之间有什么区别,但我猜测笔记本电脑上必须存在一些Windows 7依赖项。有没有人有什么建议? TIA。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值