added cpp functions for sounds
This commit is contained in:
parent
218ac42d6e
commit
e7fc943114
37
game/Sounds.cpp
Executable file
37
game/Sounds.cpp
Executable file
@ -0,0 +1,37 @@
|
||||
#include "Sounds.h"
|
||||
#include <jni.h>
|
||||
|
||||
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();
|
||||
}
|
7
game/Sounds.h
Executable file
7
game/Sounds.h
Executable file
@ -0,0 +1,7 @@
|
||||
#include <jni.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT void JNICALL Java_fishrungames_doublehitballs_sounds_JniSoundCalls_initJniSounds(JNIEnv *pEnv, jobject pThis);
|
||||
|
||||
}
|
@ -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
|
||||
|
||||
)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -6,7 +6,6 @@ public class JniWrapper
|
||||
System.loadLibrary("DoubleHitBalls");
|
||||
}
|
||||
|
||||
|
||||
public static native void Init(int width, int height);
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user