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
This commit is contained in:
parent
7610bfb7aa
commit
58684996f9
Binary file not shown.
@ -15,6 +15,7 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.jme3.audio.AudioRenderer;
|
||||
import com.jme3.audio.android.AndroidAudioRenderer;
|
||||
import com.jme3.audio.android.AndroidOpenALSoftAudioRenderer;
|
||||
import com.jme3.input.JoyInput;
|
||||
import com.jme3.input.TouchInput;
|
||||
import com.jme3.input.android.AndroidSensorJoyInput;
|
||||
@ -486,6 +487,10 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
||||
AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
|
||||
renderer.resumeAll();
|
||||
}
|
||||
if (result instanceof AndroidOpenALSoftAudioRenderer) {
|
||||
AndroidOpenALSoftAudioRenderer renderer = (AndroidOpenALSoftAudioRenderer) result;
|
||||
renderer.resumeAll();
|
||||
}
|
||||
}
|
||||
//resume the sensors (aka joysticks)
|
||||
if (app.getContext() != null) {
|
||||
@ -525,6 +530,10 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
||||
AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
|
||||
renderer.pauseAll();
|
||||
}
|
||||
if (result instanceof AndroidOpenALSoftAudioRenderer) {
|
||||
AndroidOpenALSoftAudioRenderer renderer = (AndroidOpenALSoftAudioRenderer) result;
|
||||
renderer.pauseAll();
|
||||
}
|
||||
}
|
||||
//pause the sensors (aka joysticks)
|
||||
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) {
|
||||
int errorCode = alGetError();
|
||||
String errorText = AL.GetALErrorMsg(errorCode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user