- adapt AndroidAudioRenderer to new AudioSource

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10420 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 12 years ago
parent 651734af98
commit 55d3153721
  1. 34
      engine/src/android/com/jme3/audio/android/AndroidAudioRenderer.java

@ -40,7 +40,7 @@ import android.media.MediaPlayer;
import android.media.SoundPool; import android.media.SoundPool;
import com.jme3.asset.AssetKey; import com.jme3.asset.AssetKey;
import com.jme3.audio.*; import com.jme3.audio.*;
import com.jme3.audio.AudioNode.Status; import com.jme3.audio.AudioSource.Status;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import java.io.IOException; import java.io.IOException;
@ -59,13 +59,13 @@ public class AndroidAudioRenderer implements AudioRenderer,
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 static int MAX_NUM_CHANNELS = 16;
private final HashMap<AudioNode, MediaPlayer> musicPlaying = new HashMap<AudioNode, MediaPlayer>(); private final HashMap<AudioSource, MediaPlayer> musicPlaying = new HashMap<AudioSource, MediaPlayer>();
private SoundPool soundPool = null; private SoundPool soundPool = null;
private final Vector3f listenerPosition = new Vector3f(); private final Vector3f listenerPosition = new Vector3f();
// For temp use // For temp use
private final Vector3f distanceVector = new Vector3f(); private final Vector3f distanceVector = new Vector3f();
private final AssetManager assetManager; private final AssetManager assetManager;
private HashMap<Integer, AudioNode> soundpoolStillLoading = new HashMap<Integer, AudioNode>(); private HashMap<Integer, AudioSource> soundpoolStillLoading = new HashMap<Integer, AudioSource>();
private Listener listener; private Listener listener;
private boolean audioDisabled = false; private boolean audioDisabled = false;
private final AudioManager manager; private final AudioManager manager;
@ -84,7 +84,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
} }
@Override @Override
public void updateSourceParam(AudioNode src, AudioParam param) { public void updateSourceParam(AudioSource src, AudioParam param) {
if (audioDisabled) { if (audioDisabled) {
return; return;
} }
@ -99,7 +99,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
return; return;
} }
Vector3f pos = src.getWorldTranslation(); Vector3f pos = src.getPosition();
break; break;
case Velocity: case Velocity:
if (!src.isPositional()) { if (!src.isPositional()) {
@ -220,13 +220,13 @@ public class AndroidAudioRenderer implements AudioRenderer,
float volume; float volume;
// Loop over all mediaplayers // Loop over all mediaplayers
for (AudioNode src : musicPlaying.keySet()) { for (AudioSource src : musicPlaying.keySet()) {
MediaPlayer mp = musicPlaying.get(src); MediaPlayer mp = musicPlaying.get(src);
// Calc the distance to the listener // Calc the distance to the listener
distanceVector.set(listenerPosition); distanceVector.set(listenerPosition);
distanceVector.subtractLocal(src.getLocalTranslation()); distanceVector.subtractLocal(src.getPosition());
distance = FastMath.abs(distanceVector.length()); distance = FastMath.abs(distanceVector.length());
if (distance < src.getRefDistance()) { if (distance < src.getRefDistance()) {
@ -275,7 +275,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
} }
// Cleanup media player // Cleanup media player
for (AudioNode src : musicPlaying.keySet()) { for (AudioSource src : musicPlaying.keySet()) {
MediaPlayer mp = musicPlaying.get(src); MediaPlayer mp = musicPlaying.get(src);
{ {
mp.stop(); mp.stop();
@ -294,7 +294,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
} }
// XXX: This has bad performance -> maybe change overall structure of // XXX: This has bad performance -> maybe change overall structure of
// mediaplayer in this audiorenderer? // mediaplayer in this audiorenderer?
for (AudioNode src : musicPlaying.keySet()) { for (AudioSource src : musicPlaying.keySet()) {
if (musicPlaying.get(src) == mp) { if (musicPlaying.get(src) == mp) {
src.setStatus(Status.Stopped); src.setStatus(Status.Stopped);
break; break;
@ -312,7 +312,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
* a specific streamid, so removing is not possilbe -> noone knows when * a specific streamid, so removing is not possilbe -> noone knows when
* sound finished. * sound finished.
*/ */
public void playSourceInstance(AudioNode src) { public void playSourceInstance(AudioSource src) {
if (audioDisabled) { if (audioDisabled) {
return; return;
} }
@ -357,7 +357,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
@Override @Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
AudioNode src = soundpoolStillLoading.remove(sampleId); AudioSource src = soundpoolStillLoading.remove(sampleId);
if (src == null) { if (src == null) {
logger.warning("Something went terribly wrong! onLoadComplete" logger.warning("Something went terribly wrong! onLoadComplete"
@ -376,7 +376,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
} }
} }
public void playSource(AudioNode src) { public void playSource(AudioSource src) {
if (audioDisabled) { if (audioDisabled) {
return; return;
} }
@ -414,13 +414,13 @@ public class AndroidAudioRenderer implements AudioRenderer,
} }
} }
private void setSourceParams(AudioNode src, MediaPlayer mp) { private void setSourceParams(AudioSource src, MediaPlayer mp) {
mp.setLooping(src.isLooping()); mp.setLooping(src.isLooping());
mp.setVolume(src.getVolume(), src.getVolume()); mp.setVolume(src.getVolume(), src.getVolume());
//src.getDryFilter(); //src.getDryFilter();
} }
private void setSourceParams(AudioNode src) { private void setSourceParams(AudioSource src) {
soundPool.setLoop(src.getChannel(), src.isLooping() ? -1 : 0); soundPool.setLoop(src.getChannel(), src.isLooping() ? -1 : 0);
soundPool.setVolume(src.getChannel(), src.getVolume(), src.getVolume()); soundPool.setVolume(src.getChannel(), src.getVolume(), src.getVolume());
} }
@ -452,7 +452,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
} }
} }
public void pauseSource(AudioNode src) { public void pauseSource(AudioSource src) {
if (audioDisabled) { if (audioDisabled) {
return; return;
} }
@ -469,7 +469,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
} }
} }
public void stopSource(AudioNode src) { public void stopSource(AudioSource src) {
if (audioDisabled) { if (audioDisabled) {
return; return;
} }
@ -494,7 +494,7 @@ public class AndroidAudioRenderer implements AudioRenderer,
@Override @Override
public void deleteAudioData(AudioData ad) { public void deleteAudioData(AudioData ad) {
for (AudioNode src : musicPlaying.keySet()) { for (AudioSource src : musicPlaying.keySet()) {
if (src.getAudioData() == ad) { if (src.getAudioData() == ad) {
MediaPlayer mp = musicPlaying.remove(src); MediaPlayer mp = musicPlaying.remove(src);
mp.stop(); mp.stop();

Loading…
Cancel
Save