Ah, finally back from Christmas with family (would you believe there is ZERO internet where my parents live, you can't even get a cell phone signal!)?
Finally back at the game jamming. I've been purposely vague about some aspects of the game, because being more of a story-oriented game, I don't want to reveal too much of the story so far. I will say that I'm finding myself putting more and more code in my platform-specific adapters. The next thing I wanted to do, after the player answers the fake call, is pipe the audio through the actual phone earpiece instead of the main speaker outputs. I was hoping this would be fairly simple, but it ended up taking a bit longer than I expected.
It's a fairly straightforward call that you make on the Android MediaPlayer instance, but unfortunately (for my purposes here), libGDX keeps everything really encapsulated, and doesn't expose the MediaPlayer in any way. Which means instead of being able to use libGDX's Music class, I had to have a big chunk of platform-specific code for playing the call audio. For desktop, I could still use the Music class, but for Android, I had to drop down to using the Android MediaPlayer class myself.
Actually routing the audio was pretty easy, which I'll note here for the future:
public void startPhoneCallAudio() {
mediaPlayer = new MediaPlayer();
try {
AndroidFileHandle aHandle = (AndroidFileHandle) Gdx.files.internal("audio/governmentCall.mp3");
AssetFileDescriptor descriptor = aHandle.getAssetFileDescriptor();
mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
descriptor.close();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (Exception e) {
Gdx.app.error("error", "error", e);
}
}
The other interesting platform-specific thing that I ran into was trying to spoof the nice "end of call" tone that you hear when your call ends. After some googling, it turns out that it's not an audio file, but an actual DTMF tone, which you can generate with Android's tone generator:
public void playHangupSound() {
ToneGenerator toneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, 80); //80 is volume
toneGenerator.startTone(ToneGenerator.TONE_PROP_PROMPT, 200); //200 is length
}
Other than these tweaks, I've mostly been doing UI work, trying to get things cleaned up a bit. We're getting there!