我使用Java Media Framework 2.1.1在我的应用程序中播放声音。它可以从IDE工作正常,但一旦我制作jar包。 Player
个对象无法初始化,但例外情况为:
javax.media.NoPlayerException: Cannot find a Player for :jar:file:...
我使用javax.media.Manager.createPlayer(URL sourceURL)
方法创建玩家。我怀疑jar中的URL导致了问题
有没有其他方法如何使用jar文件构建播放器?
代码:
public SoundPlayer() {
urlExplosion = ResourceLoader.getInstance().getSoundResourceUrl(SoundResource.EXPLOSION);
urlTick = ResourceLoader.getInstance().getSoundResourceUrl(SoundResource.TICK);
urlWin = ResourceLoader.getInstance().getSoundResourceUrl(SoundResource.WIN);
}
public void initialize() throws ResourceLoadingException{
try {
explosionPlayer = Manager.createPlayer(urlExplosion);
explosionPlayer.realize();
tickPlayer = Manager.createPlayer(urlTick);
tickPlayer.realize();
winPlayer = Manager.createPlayer(urlWin);
winPlayer.realize();
} catch (NoPlayerException e) {
throw new ResourceLoadingException("Could not initialize the sound player",e);
} catch (IOException e) {
throw new ResourceLoadingException("Could not initialize the sound player",e);
}
isInitialized = true;
}
注意:运行时URL不为空。
从命令行运行时出错:java -jar minesweeper.jar
Caused by: javax.media.NoPlayerException: Cannot find a Player for :jar:file:/path/to/app/minesweeper.jar!/my/package/minesweeper/gui/explosion.wav