Fixed NPE in AndroidAudioRenderer when soundPool is not initialized

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9175 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent c4231e3200
commit 446c03935e
  1. 19
      engine/src/android/com/jme3/audio/android/AndroidAudioRenderer.java

@ -60,12 +60,10 @@ import java.util.logging.Logger;
public class AndroidAudioRenderer implements AudioRenderer,
SoundPool.OnLoadCompleteListener, MediaPlayer.OnCompletionListener {
private static final Logger logger = Logger
.getLogger(AndroidAudioRenderer.class.getName());
private static final Logger logger = Logger.getLogger(AndroidAudioRenderer.class.getName());
private final static int MAX_NUM_CHANNELS = 16;
private final HashMap<AudioNode, MediaPlayer> musicPlaying = new HashMap<AudioNode, MediaPlayer>();
private SoundPool soundPool = null;
private final Vector3f listenerPosition = new Vector3f();
// For temp use
private final Vector3f distanceVector = new Vector3f();
@ -74,13 +72,11 @@ public class AndroidAudioRenderer implements AudioRenderer,
private HashMap<Integer, AudioNode> soundpoolStillLoading = new HashMap<Integer, AudioNode>();
private Listener listener;
private boolean audioDisabled = false;
private final AudioManager manager;
public AndroidAudioRenderer(Activity context) {
this.context = context;
manager = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);
manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
context.setVolumeControlStream(AudioManager.STREAM_MUSIC);
assetManager = context.getAssets();
}
@ -246,8 +242,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
}
volume = src.getRefDistance() / distance;
AndroidAudioData audioData = (AndroidAudioData) src
.getAudioData();
AndroidAudioData audioData = (AndroidAudioData) src.getAudioData();
if (FastMath.abs(audioData.getCurrentVolume() - volume) > FastMath.FLT_EPSILON) {
// Left / Right channel get the same volume by now, only
@ -413,21 +408,25 @@ public class AndroidAudioRenderer implements AudioRenderer,
* active {@link MediaPlayer}s
*/
public void pauseAll() {
if (soundPool != null) {
soundPool.autoPause();
for (MediaPlayer mp : musicPlaying.values()) {
mp.pause();
}
}
}
/**
* Resume all paused sounds.
*/
public void resumeAll() {
if (soundPool != null) {
soundPool.autoResume();
for (MediaPlayer mp : musicPlaying.values()) {
mp.start(); //no resume -> api says call start to resume
}
}
}
public void pauseSource(AudioNode src) {
if (audioDisabled) {
@ -440,9 +439,9 @@ public class AndroidAudioRenderer implements AudioRenderer,
src.setStatus(Status.Paused);
} else {
int channel = src.getChannel();
if (channel != -1)
if (channel != -1) {
soundPool.pause(channel); // is not very likley to make
// something useful :)
} // something useful :)
}
}

Loading…
Cancel
Save