* Applied android audio renderer patch (thanks to prich on the forum)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9147 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Sha..rd 13 years ago
parent f357a7e89f
commit 381a3365ef
  1. 124
      engine/src/android/com/jme3/audio/android/AndroidAudioData.java
  2. 942
      engine/src/android/com/jme3/audio/android/AndroidAudioRenderer.java
  3. 45
      engine/src/android/com/jme3/audio/plugins/AndroidAudioLoader.java

@ -1,62 +1,62 @@
package com.jme3.audio.android; package com.jme3.audio.android;
import com.jme3.asset.AssetKey; import com.jme3.asset.AssetKey;
import com.jme3.audio.AudioData; import com.jme3.audio.AudioData;
import com.jme3.audio.AudioRenderer; import com.jme3.audio.AudioRenderer;
import com.jme3.util.NativeObject; import com.jme3.util.NativeObject;
public class AndroidAudioData extends AudioData { public class AndroidAudioData extends AudioData {
protected AssetKey assetKey; protected AssetKey<?> assetKey;
protected float currentVolume = 0f; protected float currentVolume = 0f;
public AndroidAudioData(){ public AndroidAudioData(){
super(); super();
} }
protected AndroidAudioData(int id){ protected AndroidAudioData(int id){
super(id); super(id);
} }
public AssetKey getAssetKey() { public AssetKey<?> getAssetKey() {
return assetKey; return assetKey;
} }
public void setAssetKey(AssetKey assetKey) { public void setAssetKey(AssetKey<?> assetKey) {
this.assetKey = assetKey; this.assetKey = assetKey;
} }
@Override @Override
public DataType getDataType() { public DataType getDataType() {
return DataType.Buffer; return DataType.Buffer;
} }
@Override @Override
public float getDuration() { public float getDuration() {
return 0; // TODO: ??? return 0; // TODO: ???
} }
@Override @Override
public void resetObject() { public void resetObject() {
this.id = -1; this.id = -1;
setUpdateNeeded(); setUpdateNeeded();
} }
@Override @Override
public void deleteObject(Object rendererObject) { public void deleteObject(Object rendererObject) {
((AudioRenderer)rendererObject).deleteAudioData(this); ((AudioRenderer)rendererObject).deleteAudioData(this);
} }
public float getCurrentVolume() { public float getCurrentVolume() {
return currentVolume; return currentVolume;
} }
public void setCurrentVolume(float currentVolume) { public void setCurrentVolume(float currentVolume) {
this.currentVolume = currentVolume; this.currentVolume = currentVolume;
} }
@Override @Override
public NativeObject createDestructableClone() { public NativeObject createDestructableClone() {
return new AndroidAudioData(id); return new AndroidAudioData(id);
} }
} }

@ -38,6 +38,9 @@ import android.content.res.AssetManager;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.media.SoundPool; import android.media.SoundPool;
import android.util.Log;
import com.jme3.asset.AssetKey;
import com.jme3.audio.AudioNode.Status; import com.jme3.audio.AudioNode.Status;
import com.jme3.audio.*; import com.jme3.audio.*;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
@ -50,525 +53,426 @@ import java.util.logging.Logger;
/** /**
* This class is the android implementation for {@link AudioRenderer} * This class is the android implementation for {@link AudioRenderer}
*
* @author larynx * @author larynx
* * @author plan_rich
*/ */
public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadCompleteListener, MediaPlayer.OnCompletionListener { public class AndroidAudioRenderer implements AudioRenderer,
SoundPool.OnLoadCompleteListener, MediaPlayer.OnCompletionListener {
private static final Logger logger = Logger.getLogger(AndroidAudioRenderer.class.getName());
private final static int MAX_NUM_CHANNELS = 16; private static final Logger logger = Logger
private SoundPool soundPool = null; .getLogger(AndroidAudioRenderer.class.getName());
private HashMap<AudioNode, MediaPlayer> musicPlaying = new HashMap<AudioNode, MediaPlayer>(); private final static int MAX_NUM_CHANNELS = 16;
private final Vector3f listenerPosition = new Vector3f(); private final HashMap<AudioNode, MediaPlayer> musicPlaying = new HashMap<AudioNode, MediaPlayer>();
// For temp use private SoundPool soundPool = null;
private final Vector3f distanceVector = new Vector3f();
private final AudioManager manager; private final Vector3f listenerPosition = new Vector3f();
private final Context context; // For temp use
private final AssetManager am; private final Vector3f distanceVector = new Vector3f();
private HashMap<Integer, AudioNode> mapLoadingAudioNodes = new HashMap<Integer, AudioNode>(); private final Context context;
private final AtomicBoolean lastLoadCompleted = new AtomicBoolean(); private final AssetManager assetManager;
private Listener listener; private HashMap<Integer, AudioNode> soundpoolStillLoading = new HashMap<Integer, AudioNode>();
private boolean audioDisabled = false; private Listener listener;
private boolean audioDisabled = false;
public AndroidAudioRenderer(Activity context) {
this.context = context; private final AudioManager manager;
manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
context.setVolumeControlStream(AudioManager.STREAM_MUSIC); public AndroidAudioRenderer(Activity context) {
am = context.getAssets(); this.context = context;
} manager = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);
@Override context.setVolumeControlStream(AudioManager.STREAM_MUSIC);
public void initialize() { assetManager = context.getAssets();
soundPool = new SoundPool(MAX_NUM_CHANNELS, AudioManager.STREAM_MUSIC, 0); }
soundPool.setOnLoadCompleteListener(this);
} @Override
public void initialize() {
@Override soundPool = new SoundPool(MAX_NUM_CHANNELS, AudioManager.STREAM_MUSIC,
public void updateSourceParam(AudioNode src, AudioParam param) { 0);
//logger.log(Level.INFO, "updateSourceParam " + param); soundPool.setOnLoadCompleteListener(this);
}
if (audioDisabled) {
return; @Override
} public void updateSourceParam(AudioNode src, AudioParam param) {
// logger.log(Level.INFO, "updateSourceParam " + param);
if (src.getChannel() < 0) {
return; if (audioDisabled) {
} return;
}
assert src.getChannel() >= 0;
if (src.getChannel() < 0) {
return;
switch (param) { }
case Position:
if (!src.isPositional()) { switch (param) {
return; case Position:
} if (!src.isPositional()) {
return;
Vector3f pos = src.getWorldTranslation(); }
break;
case Velocity: Vector3f pos = src.getWorldTranslation();
if (!src.isPositional()) { break;
return; case Velocity:
} if (!src.isPositional()) {
return;
Vector3f vel = src.getVelocity(); }
break;
case MaxDistance: Vector3f vel = src.getVelocity();
if (!src.isPositional()) { break;
return; case MaxDistance:
} if (!src.isPositional()) {
break; return;
case RefDistance: }
if (!src.isPositional()) { break;
return; case RefDistance:
} if (!src.isPositional()) {
break; return;
case ReverbFilter: }
if (!src.isPositional() || !src.isReverbEnabled()) { break;
return; case ReverbFilter:
} if (!src.isPositional() || !src.isReverbEnabled()) {
break; return;
case ReverbEnabled: }
if (!src.isPositional()) { break;
return; case ReverbEnabled:
} if (!src.isPositional()) {
return;
if (src.isReverbEnabled()) { }
updateSourceParam(src, AudioParam.ReverbFilter);
} if (src.isReverbEnabled()) {
break; updateSourceParam(src, AudioParam.ReverbFilter);
case IsPositional: }
break; break;
case Direction: case IsPositional:
if (!src.isDirectional()) { break;
return; case Direction:
} if (!src.isDirectional()) {
return;
Vector3f dir = src.getDirection(); }
break;
case InnerAngle: Vector3f dir = src.getDirection();
if (!src.isDirectional()) { break;
return; case InnerAngle:
} if (!src.isDirectional()) {
break; return;
case OuterAngle: }
if (!src.isDirectional()) { break;
return; case OuterAngle:
} if (!src.isDirectional()) {
break; return;
case IsDirectional: }
if (src.isDirectional()) { break;
updateSourceParam(src, AudioParam.Direction); case IsDirectional:
updateSourceParam(src, AudioParam.InnerAngle); if (src.isDirectional()) {
updateSourceParam(src, AudioParam.OuterAngle); updateSourceParam(src, AudioParam.Direction);
} else { updateSourceParam(src, AudioParam.InnerAngle);
} updateSourceParam(src, AudioParam.OuterAngle);
break; } else {
case DryFilter: }
if (src.getDryFilter() != null) { break;
Filter f = src.getDryFilter(); case DryFilter:
if (f.isUpdateNeeded()) { if (src.getDryFilter() != null) {
//updateFilter(f); Filter f = src.getDryFilter();
} if (f.isUpdateNeeded()) {
} // updateFilter(f);
break; }
case Looping: }
if (src.isLooping()) { break;
} case Looping:
break; if (src.isLooping()) {
case Volume: }
break;
soundPool.setVolume(src.getChannel(), src.getVolume(), src.getVolume()); case Volume:
break; soundPool.setVolume(src.getChannel(), src.getVolume(),
case Pitch: src.getVolume());
break; break;
} case Pitch:
} break;
}
@Override
public void updateListenerParam(Listener listener, ListenerParam param) { }
//logger.log(Level.INFO, "updateListenerParam " + param);
if (audioDisabled) { @Override
return; public void updateListenerParam(Listener listener, ListenerParam param) {
} // logger.log(Level.INFO, "updateListenerParam " + param);
if (audioDisabled) {
switch (param) { return;
case Position: }
listenerPosition.set(listener.getLocation());
switch (param) {
break; case Position:
case Rotation: listenerPosition.set(listener.getLocation());
Vector3f dir = listener.getDirection();
Vector3f up = listener.getUp(); break;
case Rotation:
break; Vector3f dir = listener.getDirection();
case Velocity: Vector3f up = listener.getUp();
Vector3f vel = listener.getVelocity();
break;
break; case Velocity:
case Volume: Vector3f vel = listener.getVelocity();
//alListenerf(AL_GAIN, listener.getVolume());
break; break;
} case Volume:
// alListenerf(AL_GAIN, listener.getVolume());
} break;
}
@Override
public void update(float tpf) { }
float distance;
float volume; @Override
public void update(float tpf) {
// Loop over all mediaplayers float distance;
for (AudioNode src : musicPlaying.keySet()) { float volume;
MediaPlayer mp = musicPlaying.get(src); // Loop over all mediaplayers
{ for (AudioNode src : musicPlaying.keySet()) {
// Calc the distance to the listener
distanceVector.set(listenerPosition); MediaPlayer mp = musicPlaying.get(src);
distanceVector.subtractLocal(src.getLocalTranslation()); {
distance = FastMath.abs(distanceVector.length()); // Calc the distance to the listener
distanceVector.set(listenerPosition);
if (distance < src.getRefDistance()) { distanceVector.subtractLocal(src.getLocalTranslation());
distance = src.getRefDistance(); distance = FastMath.abs(distanceVector.length());
}
if (distance > src.getMaxDistance()) { if (distance < src.getRefDistance()) {
distance = src.getMaxDistance(); distance = src.getRefDistance();
} }
volume = src.getRefDistance() / distance; if (distance > src.getMaxDistance()) {
distance = src.getMaxDistance();
AndroidAudioData audioData = (AndroidAudioData) src.getAudioData(); }
volume = src.getRefDistance() / distance;
if (FastMath.abs(audioData.getCurrentVolume() - volume) > FastMath.FLT_EPSILON) {
// Left / Right channel get the same volume by now, only positional AndroidAudioData audioData = (AndroidAudioData) src
mp.setVolume(volume, volume); .getAudioData();
audioData.setCurrentVolume(volume); if (FastMath.abs(audioData.getCurrentVolume() - volume) > FastMath.FLT_EPSILON) {
} // Left / Right channel get the same volume by now, only
// positional
mp.setVolume(volume, volume);
}
} audioData.setCurrentVolume(volume);
} }
}
public void setListener(Listener listener) { }
if (audioDisabled) { }
return;
} public void setListener(Listener listener) {
if (audioDisabled) {
if (this.listener != null) { return;
// previous listener no longer associated with current }
// renderer
this.listener.setRenderer(null); if (this.listener != null) {
} // previous listener no longer associated with current
// renderer
this.listener = listener; this.listener.setRenderer(null);
this.listener.setRenderer(this); }
} this.listener = listener;
this.listener.setRenderer(this);
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { }
AudioNode src = mapLoadingAudioNodes.get(sampleId);
if (src.getAudioData() instanceof AndroidAudioData) { @Override
AndroidAudioData audioData = (AndroidAudioData) src.getAudioData(); public void cleanup() {
// Cleanup sound pool
if (status == 0) // load was successfull if (soundPool != null) {
{ soundPool.release();
int channelIndex; soundPool = null;
channelIndex = soundPool.play(audioData.getId(), 1f, 1f, 1, -1, 1f); }
src.setChannel(channelIndex);
// Playing started ? // Cleanup media player
if (src.getChannel() > 0) { for (AudioNode src : musicPlaying.keySet()) {
src.setStatus(Status.Playing); MediaPlayer mp = musicPlaying.get(src);
} {
} else { mp.stop();
src.setChannel(-1); mp.release();
} src.setStatus(Status.Stopped);
} else { }
throw new IllegalArgumentException("AudioData is not of type AndroidAudioData for AudioNode " + src.toString()); }
} musicPlaying.clear();
} }
@Override @Override
public void cleanup() { public void onCompletion(MediaPlayer mp) {
// Cleanup sound pool mp.seekTo(0);
if (soundPool != null) { mp.stop();
for (AudioNode src : mapLoadingAudioNodes.values()) { // XXX: This has bad performance -> maybe change overall structure of
if ((src.getStatus() == Status.Playing) && (src.getChannel() > 0)) { // mediaplayer in this audiorenderer?
soundPool.stop(src.getChannel()); for (AudioNode src : musicPlaying.keySet()) {
} if (musicPlaying.get(src) == mp) {
src.setStatus(Status.Stopped);
if (src.getAudioData() instanceof AndroidAudioData) { break;
AndroidAudioData audioData = (AndroidAudioData) src.getAudioData(); }
if (audioData.getId() > 0) { }
soundPool.unload(audioData.getId()); }
}
} /**
} * Plays using the {@link SoundPool} of Android. Due to hard limitation of
* the SoundPool: After playing more instances of the sound you only have
soundPool.release(); * the channel of the last played instance.
soundPool = null; *
} * It is not possible to get information about the state of the soundpool of
* a specific streamid, so removing is not possilbe -> noone knows when
// Cleanup media player * sound finished.
for (AudioNode src : musicPlaying.keySet()) { */
MediaPlayer mp = musicPlaying.get(src); public void playSourceInstance(AudioNode src) {
{ if (audioDisabled) {
mp.stop(); return;
mp.release(); }
src.setStatus(Status.Stopped);
} AndroidAudioData audioData = (AndroidAudioData) src.getAudioData();
}
musicPlaying.clear(); if (!(audioData.getAssetKey() instanceof AudioKey)) {
} throw new IllegalArgumentException("Asset is not a AudioKey");
}
@Override
public void onCompletion(MediaPlayer mp) { AudioKey assetKey = (AudioKey) audioData.getAssetKey();
for (AudioNode src : musicPlaying.keySet()) {
if (musicPlaying.get(src) == mp) { try {
mp.seekTo(0); if (audioData.getId() < 0) { // found something to load
mp.stop(); int soundId = soundPool.load(
src.setStatus(Status.Stopped); assetManager.openFd(assetKey.getName()), 1);
break; audioData.setId(soundId);
} }
}
int channel = soundPool.play(audioData.getId(), 1f, 1f, 1, 0, 1f);
}
if (channel == 0) {
public void playSourceInstance(AudioNode src) { soundpoolStillLoading.put(audioData.getId(), src);
if (audioDisabled) { } else {
return; src.setChannel(channel); // receive a channel at the last
} // playing at least
}
AndroidAudioData audioData; } catch (IOException e) {
int soundId = 0; logger.log(Level.SEVERE,
"Failed to load sound " + assetKey.getName(), e);
if (src.getAudioData() instanceof AndroidAudioData) { audioData.setId(-1);
audioData = (AndroidAudioData) src.getAudioData(); }
}
if (audioData.getAssetKey() instanceof AudioKey) {
AudioKey assetKey = (AudioKey) audioData.getAssetKey(); @Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
// streaming audionodes get played using android mediaplayer, non streaming uses SoundPool AudioNode src = soundpoolStillLoading.remove(sampleId);
if (assetKey.isStream()) {
MediaPlayer mp; if (src == null) {
if (musicPlaying.containsKey(src)) { logger.warning("Something went terribly wrong! onLoadComplete"
mp = musicPlaying.get(src); + " had sampleId which was not in the HashMap of loading items");
} else { return;
mp = new MediaPlayer(); }
mp.setOnCompletionListener(this);
//mp = MediaPlayer.create(context, new Ur ); AudioData audioData = src.getAudioData();
musicPlaying.put(src, mp);
} if (status == 0) // load was successfull
if (!mp.isPlaying()) { {
try { int channelIndex;
AssetFileDescriptor afd = am.openFd(assetKey.getName()); channelIndex = soundPool.play(audioData.getId(), 1f, 1f, 1, 0, 1f);
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); src.setChannel(channelIndex);
}
mp.setAudioStreamType(AudioManager.STREAM_MUSIC); }
mp.prepare();
mp.setLooping(src.isLooping()); public void playSource(AudioNode src) {
mp.start(); if (audioDisabled) {
src.setChannel(1); return;
src.setStatus(Status.Playing); }
} catch (IllegalArgumentException e) {
logger.log(Level.SEVERE, "Failed to play " + assetKey.getName(), e); AndroidAudioData audioData = (AndroidAudioData) src.getAudioData();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block MediaPlayer mp = musicPlaying.get(src);
logger.log(Level.SEVERE, "Failed to play " + assetKey.getName(), e); if (mp == null) {
} catch (IOException e) { mp = new MediaPlayer();
// TODO Auto-generated catch block mp.setOnCompletionListener(this);
logger.log(Level.SEVERE, "Failed to play " + assetKey.getName(), e); mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
} }
} try {
AssetKey<?> key = audioData.getAssetKey();
} else {
// Low latency Sound effect using SoundPool AssetFileDescriptor afd = assetManager.openFd(key.getName()); // assetKey.getName()
if (audioData.isUpdateNeeded() || (audioData.getId() <= 0)) { mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(),
if (audioData.getId() > 0) { afd.getLength());
if (src.getChannel() > 0) { mp.prepare();
soundPool.stop(src.getChannel()); mp.setLooping(src.isLooping());
src.setChannel(-1); mp.start();
} src.setChannel(0);
soundPool.unload(audioData.getId()); src.setStatus(Status.Playing);
} musicPlaying.put(src, mp);
try { } catch (IllegalStateException e) {
soundId = soundPool.load(am.openFd(assetKey.getName()), 1); e.printStackTrace();
} catch (IOException e) { } catch (Exception e) {
logger.log(Level.SEVERE, "Failed to load sound " + assetKey.getName(), e); e.printStackTrace();
soundId = -1; }
} }
audioData.setId(soundId);
} public void pauseSource(AudioNode src) {
if (audioDisabled) {
// Sound failed to load ? return;
if (audioData.getId() <= 0) { }
throw new IllegalArgumentException("Failed to load: " + assetKey.getName());
} else { MediaPlayer mp = musicPlaying.get(src);
int channelIndex; if (mp != null) {
channelIndex = soundPool.play(audioData.getId(), 1f, 1f, 1, -1, 1f); mp.pause();
if (channelIndex == 0) { src.setStatus(Status.Paused);
// Loading is not finished } else {
// Store the soundId and the AudioNode for async loading and later play start int channel = src.getChannel();
mapLoadingAudioNodes.put(audioData.getId(), src); if (channel != -1)
} soundPool.pause(channel); // is not very likley to make
src.setChannel(channelIndex); // something useful :)
} }
}
// Playing started ?
if (src.getChannel() > 0) { public void stopSource(AudioNode src) {
src.setStatus(Status.Playing); if (audioDisabled) {
} return;
} }
} // can be stream or buffer -> so try to get mediaplayer
} else { // if there is non try to stop soundpool
throw new IllegalArgumentException("AudioData is not of type AndroidAudioData for AudioNode " + src.toString()); MediaPlayer mp = musicPlaying.get(src);
} if (mp != null) {
mp.stop();
src.setStatus(Status.Paused);
} else {
} int channel = src.getChannel();
if (channel != -1) {
public void playSource(AudioNode src) { soundPool.pause(channel); // is not very likley to make
if (audioDisabled) { // something useful :)
return; }
} }
//assert src.getStatus() == Status.Stopped || src.getChannel() == -1; }
if (src.getStatus() == Status.Playing) { @Override
return; public void deleteAudioData(AudioData ad) {
} else if (src.getStatus() == Status.Stopped) {
playSourceInstance(src); for (AudioNode src : musicPlaying.keySet()) {
} if (src.getAudioData() == ad) {
MediaPlayer mp = musicPlaying.remove(src);
mp.stop();
} mp.release();
src.setStatus(Status.Stopped);
public void pauseSource(AudioNode src) { src.setChannel(-1);
if (audioDisabled) { ad.setId(-1);
return; break;
} }
}
if (src.getStatus() == Status.Playing) {
if (src.getAudioData() instanceof AndroidAudioData) { if (ad.getId() > 0) {
AndroidAudioData audioData = (AndroidAudioData) src.getAudioData(); soundPool.unload(ad.getId());
if (audioData.getAssetKey() instanceof AudioKey) { ad.setId(-1);
AudioKey assetKey = (AudioKey) audioData.getAssetKey(); }
}
if (assetKey.isStream()) {
MediaPlayer mp; @Override
if (musicPlaying.containsKey(src)) { public void setEnvironment(Environment env) {
mp = musicPlaying.get(src); //not yet supported
mp.pause(); }
src.setStatus(Status.Paused);
} @Override
} else { public void deleteFilter(Filter filter) {
assert src.getChannel() != -1; }
if (src.getChannel() > 0) {
soundPool.pause(src.getChannel());
src.setStatus(Status.Paused);
}
}
}
}
}
}
public void stopSource(AudioNode src) {
if (audioDisabled) {
return;
}
if (src.getStatus() != Status.Stopped) {
if (src.getAudioData() instanceof AndroidAudioData) {
AndroidAudioData audioData = (AndroidAudioData) src.getAudioData();
if (audioData.getAssetKey() instanceof AudioKey) {
AudioKey assetKey = (AudioKey) audioData.getAssetKey();
if (assetKey.isStream()) {
MediaPlayer mp;
if (musicPlaying.containsKey(src)) {
mp = musicPlaying.get(src);
mp.stop();
src.setStatus(Status.Stopped);
src.setChannel(-1);
}
} else {
int chan = src.getChannel();
assert chan != -1; // if it's not stopped, must have id
if (src.getChannel() > 0) {
soundPool.stop(src.getChannel());
src.setChannel(-1);
}
src.setStatus(Status.Stopped);
if (audioData.getId() > 0) {
soundPool.unload(audioData.getId());
}
audioData.setId(-1);
}
}
}
}
}
public void updateAudioData(AndroidAudioData data) {
throw new UnsupportedOperationException("updateAudioData");
}
public void deleteFilter(Filter filter) {
}
@Override
public void deleteAudioData(AudioData ad) {
if (ad instanceof AndroidAudioData) {
AndroidAudioData audioData = (AndroidAudioData) ad;
if (audioData.getAssetKey() instanceof AudioKey) {
AudioKey assetKey = (AudioKey) audioData.getAssetKey();
if (assetKey.isStream()) {
for (AudioNode src : musicPlaying.keySet()) {
if (src.getAudioData() == ad) {
MediaPlayer mp = musicPlaying.get(src);
mp.stop();
mp.release();
musicPlaying.remove(src);
src.setStatus(Status.Stopped);
src.setChannel(-1);
break;
}
}
} else {
if (audioData.getId() > 0) {
soundPool.unload(audioData.getId());
}
audioData.setId(0);
}
}
} else {
throw new IllegalArgumentException("AudioData is not of type AndroidAudioData in deleteAudioData");
}
}
@Override
public void setEnvironment(Environment env) {
// TODO Auto-generated method stub
}
} }

@ -1,26 +1,19 @@
package com.jme3.audio.plugins; package com.jme3.audio.plugins;
import com.jme3.asset.AssetInfo; import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetLoader; import com.jme3.asset.AssetLoader;
import com.jme3.audio.android.AndroidAudioData; import com.jme3.audio.android.AndroidAudioData;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
public class AndroidAudioLoader implements AssetLoader
public class AndroidAudioLoader implements AssetLoader {
{
@Override
@Override public Object load(AssetInfo assetInfo) throws IOException
public Object load(AssetInfo assetInfo) throws IOException {
{ AndroidAudioData result = new AndroidAudioData();
result.setAssetKey( assetInfo.getKey() );
InputStream in = assetInfo.openStream(); return result;
if (in != null) }
{
in.close(); }
}
AndroidAudioData result = new AndroidAudioData();
result.setAssetKey( assetInfo.getKey() );
return result;
}
}

Loading…
Cancel
Save