I have an app that plays sounds on button press. These sounds loop continuously and are between 10-20 seconds long.
Everything works exactly as it should, however whenever I lock my phone by pressing the power button (lock button), the MediaPlayer starts to lag and the looping is no longer seamless or continuous and so there is a clear gap between each loop.
I'm using ogg files and when the screen is on there is no noticeable gap.
This leads to believe I need a wakelock to ensure the CPU is kept on, however even by using this, there is still noticeable and significant lag from the MediaPlayer when the phone is locked.
This is how I'm calling wakelock. Has anyone had this same issue before?
// Create a new MediaPlayer to play this sound
mp = MediaPlayer.create(this, resId);
mp.setLooping(true);
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"MyWakelockTag");
wakeLock.acquire();
mp.start();