I'm having a problem with my app when I try to stream musics on background and it only occurs on some devices.
When the app plays any music on foreground it works without problems, but in some devices, when I press the power button, the stream immediately loses its quality (looks like when I'm on a low speed internet connection). When I turn on the screen the stream gets better again.
I've already tried WakeLocks
but it didn't work.
Edit 1: This is how I used the wake locks:
OnCreate
of my activity:
//Setting the wakelock
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
and than I do this when the music starts:
wl.acquire();
and this when the stream stops:
if(wl.isHeld()){
wl.release();
}
Edit 2:
Tried this as well:
mediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
Edit 3:
Tried with WiFi Locks too:
//Setting the proper lockMode depending on the android version:
int wifiLockMode = WifiManager.WIFI_MODE_FULL;
int sdkVersion = Build.VERSION.SDK_INT;
//WIFI_MODE_FULL_HIGH_PERF was added on Android 3.1 so
//I need to implement this to make sure the wifi will execute on its full power(even if it consumes more battery)
if (sdkVersion >= Build.VERSION_CODES.HONEYCOMB_MR1) {
wifiLockMode = WifiManager.WIFI_MODE_FULL_HIGH_PERF;
}
//Setting the WifiLock
WiFiManager wm = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
WifiLock mWiFiLock = wm.createWifiLock(wifiLockMode, "MyFlag");
mWiFiLock.acquire();
//Releasing the WifiLock
if(mWiFiLock.isHeld()){
mWiFiLock.release();
}
With the WifiLock it seems to be a little better(or I'm getting used to the interrupted sound)
Any ideas?