diff --git a/game/Sounds.cpp b/game/Sounds.cpp new file mode 100755 index 0000000..36dfbca --- /dev/null +++ b/game/Sounds.cpp @@ -0,0 +1,37 @@ +#include "Sounds.h" +#include + +static JNIEnv* env = NULL; +static jclass jSounds = NULL; + +/** BackgroundSound */ + +void playBackgroundSound() { + jmethodID method = env->GetStaticMethodID(jSounds, "JniPlayBackgroundSound", "()V"); + env->CallStaticVoidMethod(jSounds, method); +} + +void stopBackgroundSound () { + jmethodID method = env->GetStaticMethodID(jSounds, "JniStopBackgroundSound", "()V"); + env->CallStaticVoidMethod(jSounds, method); +} + +/** GameSound - Gunshot */ + +void playGameSoundGunshot() { + jmethodID method = env->GetStaticMethodID(jSounds, "JniPlayGunshotSound", "()V"); + env->CallStaticVoidMethod(jSounds, method); +} + +void stopGameSoundGunshot() { + jmethodID method = env->GetStaticMethodID(jSounds, "JniStopGunshotSound", "()V"); + env->CallStaticVoidMethod(jSounds, method); +} + +JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_sounds_JniSoundCalls_initJniSounds(JNIEnv *pEnv, jobject pThis) { + env = pEnv; + jSounds = env->FindClass("fishrungames/doublehitballs/sounds/JniSoundCalls"); + playBackgroundSound(); + playGameSoundGunshot(); + stopBackgroundSound(); +} \ No newline at end of file diff --git a/game/Sounds.h b/game/Sounds.h new file mode 100755 index 0000000..66f7b95 --- /dev/null +++ b/game/Sounds.h @@ -0,0 +1,7 @@ +#include + +extern "C" { + +JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_sounds_JniSoundCalls_initJniSounds(JNIEnv *pEnv, jobject pThis); + +} diff --git a/proj.android-studio/app/CMakeLists.txt b/proj.android-studio/app/CMakeLists.txt index 13adfe5..f814c6c 100755 --- a/proj.android-studio/app/CMakeLists.txt +++ b/proj.android-studio/app/CMakeLists.txt @@ -42,6 +42,7 @@ add_library(DoubleHitBalls SHARED ${CMAKE_CURRENT_SOURCE_DIR}/../../game/gamecode.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../game/loadingcode.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../game/menucode.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../../game/Sounds.cpp ) diff --git a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GLView.java b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GLView.java index ab012e3..a35a556 100755 --- a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GLView.java +++ b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/GLView.java @@ -9,6 +9,7 @@ import android.opengl.GLSurfaceView; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; +import fishrungames.doublehitballs.sounds.JniSoundCalls; import fishrungames.salmonengineandroid.GLViewAncestor; import fishrungames.salmonengineandroid.EngineWrapper; @@ -59,6 +60,7 @@ class GLView extends GLViewAncestor public void onSurfaceChanged(GL10 gl, int width, int height) { JniWrapper.Init(width,height); + JniSoundCalls.init(); } public void onSurfaceCreated(GL10 gl, EGLConfig config) diff --git a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/JniWrapper.java b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/JniWrapper.java index 8e73337..d2b6498 100755 --- a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/JniWrapper.java +++ b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/JniWrapper.java @@ -6,7 +6,6 @@ public class JniWrapper System.loadLibrary("DoubleHitBalls"); } - public static native void Init(int width, int height); } \ No newline at end of file diff --git a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/sounds/JniSoundCalls.java b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/sounds/JniSoundCalls.java index c248e39..ebe046a 100644 --- a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/sounds/JniSoundCalls.java +++ b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/sounds/JniSoundCalls.java @@ -1,11 +1,49 @@ package fishrungames.doublehitballs.sounds; -public interface JniSoundCalls { +import android.media.MediaPlayer; - void playBackgroundSound(); - void stopBackgroundSound(); +import fishrungames.doublehitballs.GL2JNIActivity; +import fishrungames.doublehitballs.R; - void playGunshotSound(); - void stopGunshotSound(); +/** + * example sounds for JNI calls + * @author Artem Budarin + * Created by Artem Budarin on 06.08.2018. + */ + +public class JniSoundCalls { + + native public static void initJniSounds(); + + private static MediaPlayer backgroundPlayer = null; + private static MediaPlayer gunshotPlayer = null; + + public static void init() { + initJniSounds(); + } + + public static void JniPlayBackgroundSound() { + backgroundPlayer = MediaPlayer.create(GL2JNIActivity.getInstance(), R.raw.background_sound); + backgroundPlayer.setLooping(true); + backgroundPlayer.start(); + } + + public static void JniStopBackgroundSound() { + if (backgroundPlayer != null) { + backgroundPlayer.stop(); + } + } + + public static void JniPlayGunshotSound() { + gunshotPlayer = MediaPlayer.create(GL2JNIActivity.getInstance(), R.raw.gunshot_sound); + gunshotPlayer.setLooping(false); + gunshotPlayer.start(); + } + + public static void JniStopGunshotSound() { + if (gunshotPlayer != null) { + gunshotPlayer.stop(); + } + } } diff --git a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/sounds/JniSoundCallsImpl.java b/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/sounds/JniSoundCallsImpl.java deleted file mode 100644 index e5a6b39..0000000 --- a/proj.android-studio/app/src/main/java/fishrungames/doublehitballs/sounds/JniSoundCallsImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -package fishrungames.doublehitballs.sounds; - -import android.media.MediaPlayer; - -import fishrungames.doublehitballs.GL2JNIActivity; -import fishrungames.doublehitballs.R; - -/** - * example sounds for JNI calls - * @author Artem Budarin - * Created by Artem Budarin on 06.08.2018. - */ - -public class JniSoundCallsImpl implements JniSoundCalls { - - private MediaPlayer backgroundPlayer = null; - private MediaPlayer gunshotPlayer = null; - - @Override - public void playBackgroundSound() { - backgroundPlayer = MediaPlayer.create(GL2JNIActivity.getInstance(), R.raw.background_sound); - backgroundPlayer.setLooping(true); - backgroundPlayer.start(); - } - - @Override - public void stopBackgroundSound() { - if (backgroundPlayer != null) { - backgroundPlayer.stop(); - } - } - - @Override - public void playGunshotSound() { - gunshotPlayer = MediaPlayer.create(GL2JNIActivity.getInstance(), R.raw.gunshot_sound); - gunshotPlayer.setLooping(false); - gunshotPlayer.start(); - } - - @Override - public void stopGunshotSound() { - if (gunshotPlayer != null) { - gunshotPlayer.stop(); - } - } - -}