|
|
|
@ -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 :)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|