Just figured it out!. The background sound won't play if mediaplayer is set in onStop, onResume and onPause. The only code required is in onDestroy (stop the sound when app is killed). The standalones all set it in all ons coz most have buttons to play and pause. Very simple code too, just a few lines for background sound to play continuously.
For mp3 format, i'm more familiar with mp3 than ogg and I can fine tune the audio such as resample it to VBR to reduce size without losing too much quality. The mp3 was 1.4mb, ogg was 1.5mb but resampled mp3 is now 710kb for a 92sec of audio (minimal loss). Besides, i may test the java code with j2objc soon and i heard that ios don't do ogg.
Btw, lets look at the code:
..
import android.media.MediaPlayer; // 1st line needed
..
public class Your3Dapp extends Activity {
..
MediaPlayer mediaPlayer; // 2nd line
int soundID = 1; // optional
..
protected void onCreate(Bundle savedInstanceState) {
--
mediaPlayer = MediaPlayer.create(this, R.raw.the_sound); // 3rd line
mediaPlayer.start(); // 4th line
mediaPlayer.setLooping(true); // optional
mediaPlayer.setVolume(100,100); // optional
..
protected void onPause() { // leave this alone
Logger.log("onPause");
super.onPause();
mGLView.onPause();
}
@Override
protected void onResume() {
Logger.log("onResume");
super.onResume();
mGLView.onResume();
}
protected void onStop() { // leave this alone
Logger.log("onStop");
super.onStop();
}
protected void onDestroy() {
if(mediaPlayer != null) // 5th line needed
{
try{
mediaPlayer.stop(); // 6th line
mediaPlayer.release(); // 7th line
}finally {
mediaPlayer = null; // 8th line
}
super.onDestroy();
}
}
..