瀏覽代碼

solve issue #1963 (TestMusicPlayer fails to load AL library on lwjgl2) (#1964)

* TestMusicPlayer: fix UnsatisfiedLinkError when using lwjgl2. Solves issue #1963

* Add missing load function for "openal" natives.

* Removed the unnecessary check for lwjgl 2 in classpath.

* Fix comment
Ali-RS 2 年之前
父節點
當前提交
49efb4d2a1
共有 1 個文件被更改,包括 14 次插入1 次删除
  1. 14 1
      jme3-examples/src/main/java/jme3test/audio/TestMusicPlayer.java

+ 14 - 1
jme3-examples/src/main/java/jme3test/audio/TestMusicPlayer.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2021 jMonkeyEngine
+ * Copyright (c) 2009-2023 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -40,6 +40,8 @@ import com.jme3.audio.plugins.OGGLoader;
 import com.jme3.audio.plugins.WAVLoader;
 import com.jme3.system.AppSettings;
 import com.jme3.system.JmeSystem;
+import com.jme3.system.NativeLibraryLoader;
+
 import java.io.*;
 import javax.swing.JFileChooser;
 
@@ -52,6 +54,17 @@ public class TestMusicPlayer extends javax.swing.JFrame {
     private float curTime = 0;
     final private Listener listener = new Listener();
 
+    static {
+        // Load lwjgl and openal natives if lwjgl version 2 is in classpath.
+        //
+        // In case of lwjgl 2, natives are loaded when LwjglContext is
+        // started, but in this test we do not create a LwjglContext,
+        // so we should handle loading natives ourselves if running
+        // with lwjgl 2.
+        NativeLibraryLoader.loadNativeLibrary("lwjgl", false);
+        NativeLibraryLoader.loadNativeLibrary("openal", false);
+    }
+
     public TestMusicPlayer() {
         initComponents();
         setLocationRelativeTo(null);