added example sounds for JNI calls

This commit is contained in:
Artem Budarin 2018-08-07 23:01:35 +05:00
parent 69cb2f7cd3
commit 128c330f48
5 changed files with 68 additions and 1 deletions

View File

@ -20,6 +20,8 @@ import android.view.MotionEvent;
public class GL2JNIActivity extends Activity public class GL2JNIActivity extends Activity
{ {
private static GL2JNIActivity instance;
GLView mView; GLView mView;
@ -28,7 +30,9 @@ public class GL2JNIActivity extends Activity
{ {
super.onCreate(icicle); super.onCreate(icicle);
instance = this;
EngineWrapper.LoadSalmonEngineLibrary(); EngineWrapper.LoadSalmonEngineLibrary();
EngineWrapper.SetActivityInstance(this); EngineWrapper.SetActivityInstance(this);
EngineWrapper.SetupEnviroment(); EngineWrapper.SetupEnviroment();
@ -88,4 +92,9 @@ public class GL2JNIActivity extends Activity
EngineWrapper.ProcessKeyDown(keyCode, event); EngineWrapper.ProcessKeyDown(keyCode, event);
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
public static GL2JNIActivity getInstance() {
return instance;
}
} }

View File

@ -0,0 +1,11 @@
package fishrungames.doublehitballs.sounds;
public interface JniSoundCalls {
void playBackgroundSound();
void stopBackgroundSound();
void playGunshotSound();
void stopGunshotSound();
}

View File

@ -0,0 +1,47 @@
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();
}
}
}

Binary file not shown.