added cpp functions for sounds

This commit is contained in:
artem.budarin committed 2018-08-12 19:16:12 +05:00
1 parent 218ac42d6e
commit e7fc943114
7 files changed
+90 -53

No files matched your search

+1
View File
@@ -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();
}
}
}