我正在尝试使用以下命令在程序的后台播放一个简单的mp3:
Media med = new Media(getClass().getResource("intro.mp3").toExternalForm()); MediaPlayer mPlayer = new MediaPlayer(med); mPlayer.play();
intro.mp3文件与其他.class文件放在我的包的bin文件夹中。
问题是我的程序终止于:
Exception in thread "main" java.lang.IllegalStateException: Toolkit not initialized
完整的终止日志为:
Device "Intel(R) HD Graphics Family" (\\.\DISPLAY1) initialization failed : WARNING: bad driver version detected, device disabled. Please update your driver to at least version 8.15.10.2302 Exception in thread "main" java.lang.IllegalStateException: Toolkit not initialized at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:153) at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:148) at javafx.application.Platform.runLater(Platform.java:52) at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:450) at javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:365) at PokerApp.<init>(PokerApp.java:33) at PokerApp.main(PokerApp.java:105)
根据问题的原因有人有想法吗?
JavaFX在启动时执行“隐藏”初始化。运行MediaPlayer不会触发初始化。
JavaFX
MediaPlayer
触发它的最简单方法是:
Application.launch()
Application
Platform.startup(Runnable)