Android: Added methods for OpenAL Soft Audio Renderer to pause and resume audio when app is placed in the background

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10613 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
iwg..om 12 years ago
parent 7610bfb7aa
commit 58684996f9
  1. BIN
      engine/lib/openal-soft/jME3-openal-soft-natives-android.jar
  2. 9
      engine/src/android/com/jme3/app/AndroidHarness.java
  3. 63
      engine/src/android/com/jme3/audio/android/AndroidOpenALSoftAudioRenderer.java

@ -15,6 +15,7 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.jme3.audio.AudioRenderer; import com.jme3.audio.AudioRenderer;
import com.jme3.audio.android.AndroidAudioRenderer; import com.jme3.audio.android.AndroidAudioRenderer;
import com.jme3.audio.android.AndroidOpenALSoftAudioRenderer;
import com.jme3.input.JoyInput; import com.jme3.input.JoyInput;
import com.jme3.input.TouchInput; import com.jme3.input.TouchInput;
import com.jme3.input.android.AndroidSensorJoyInput; import com.jme3.input.android.AndroidSensorJoyInput;
@ -486,6 +487,10 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
renderer.resumeAll(); renderer.resumeAll();
} }
if (result instanceof AndroidOpenALSoftAudioRenderer) {
AndroidOpenALSoftAudioRenderer renderer = (AndroidOpenALSoftAudioRenderer) result;
renderer.resumeAll();
}
} }
//resume the sensors (aka joysticks) //resume the sensors (aka joysticks)
if (app.getContext() != null) { if (app.getContext() != null) {
@ -525,6 +530,10 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
renderer.pauseAll(); renderer.pauseAll();
} }
if (result instanceof AndroidOpenALSoftAudioRenderer) {
AndroidOpenALSoftAudioRenderer renderer = (AndroidOpenALSoftAudioRenderer) result;
renderer.pauseAll();
}
} }
//pause the sensors (aka joysticks) //pause the sensors (aka joysticks)
if (app.getContext() != null) { if (app.getContext() != null) {

@ -1299,6 +1299,69 @@ public class AndroidOpenALSoftAudioRenderer implements AudioRenderer, Runnable {
} }
} }
public void pauseAll() {
checkDead();
synchronized (threadLock) {
while (!threadLock.get()) {
try {
threadLock.wait();
} catch (InterruptedException ex) {
}
}
if (audioDisabled) {
return;
}
for (int i = 0; i < channels.length; i++) {
AudioSource src = chanSrcs[i];
if (src == null) {
continue;
}
if (src.getStatus() == Status.Playing) {
assert src.getChannel() != -1;
logger.log(Level.FINE, "Pausing Source: {0}", src.getChannel());
alSourcePause(channels[src.getChannel()]);
checkError(true);
src.setStatus(Status.Paused);
}
}
}
}
public void resumeAll() {
checkDead();
synchronized (threadLock) {
while (!threadLock.get()) {
try {
threadLock.wait();
} catch (InterruptedException ex) {
}
}
if (audioDisabled) {
return;
}
for (int i = 0; i < channels.length; i++) {
AudioSource src = chanSrcs[i];
if (src == null) {
continue;
}
if (src.getStatus() == Status.Paused) {
assert src.getChannel() != -1;
logger.log(Level.FINE, "Playing/Resuming Source: {0}", src.getChannel());
alSourcePlay(channels[src.getChannel()]);
checkError(true);
src.setStatus(Status.Playing);
}
}
}
}
private int checkError(boolean stopOnError) { private int checkError(boolean stopOnError) {
int errorCode = alGetError(); int errorCode = alGetError();
String errorText = AL.GetALErrorMsg(errorCode); String errorText = AL.GetALErrorMsg(errorCode);

Loading…
Cancel
Save