Merge pull request #1198 from mfietz/issue/1110-wake-lock
Do not acquire wakelock when Prestissimo backed mediaplayer is created
This commit is contained in:
commit
e3513c783b
|
@ -20,8 +20,6 @@
|
|||
|
||||
package com.aocate.media;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -30,8 +28,8 @@ import android.media.AudioManager;
|
|||
import android.net.Uri;
|
||||
import android.os.IBinder;
|
||||
import android.os.PowerManager;
|
||||
import android.os.RemoteException;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.aocate.media.MediaPlayer.State;
|
||||
|
@ -46,6 +44,8 @@ import com.aocate.presto.service.IOnSeekCompleteListenerCallback_0_8;
|
|||
import com.aocate.presto.service.IOnSpeedAdjustmentAvailableChangedListenerCallback_0_8;
|
||||
import com.aocate.presto.service.IPlayMedia_0_8;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import de.danoeh.antennapod.core.BuildConfig;
|
||||
|
||||
/**
|
||||
|
@ -60,7 +60,7 @@ import de.danoeh.antennapod.core.BuildConfig;
|
|||
public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
||||
static final String INTENT_NAME = "com.aocate.intent.PLAY_AUDIO_ADJUST_SPEED_0_8";
|
||||
|
||||
private static final String SBMP_TAG = "AocateServiceBackedMediaPlayer";
|
||||
private static final String SBMP_TAG = "ServiceBackedMediaPlaye";
|
||||
|
||||
private ServiceConnection mPlayMediaServiceConnection = null;
|
||||
protected IPlayMedia_0_8 pmInterface = null;
|
||||
|
@ -874,19 +874,24 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
|||
// the client app's responsibility to request that permission
|
||||
public void setWakeMode(Context context, int mode) {
|
||||
Log.d(SBMP_TAG, "setWakeMode(context, " + mode + ")");
|
||||
if ((this.mWakeLock != null)
|
||||
&& (this.mWakeLock.isHeld())) {
|
||||
this.mWakeLock.release();
|
||||
boolean wasHeld = false;
|
||||
if (mWakeLock != null) {
|
||||
if(mWakeLock.isHeld()) {
|
||||
wasHeld = true;
|
||||
Log.d(SBMP_TAG, "Releasing wakelock");
|
||||
mWakeLock.release();
|
||||
}
|
||||
mWakeLock = null;
|
||||
}
|
||||
if (mode != 0) {
|
||||
if (this.mWakeLock == null) {
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
// Since mode can't be changed on the fly, we have to allocate a new one
|
||||
this.mWakeLock = pm.newWakeLock(mode, this.getClass().getName());
|
||||
this.mWakeLock.setReferenceCounted(false);
|
||||
}
|
||||
mWakeLock = pm.newWakeLock(mode, this.getClass().getName());
|
||||
mWakeLock.setReferenceCounted(false);
|
||||
|
||||
this.mWakeLock.acquire();
|
||||
if(wasHeld) {
|
||||
Log.d(SBMP_TAG, "Acquiring wakelock");
|
||||
mWakeLock.acquire();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -898,8 +903,10 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
|||
if (BuildConfig.DEBUG) Log.d(SBMP_TAG, "stayAwake(" + awake + ")");
|
||||
if (mWakeLock != null) {
|
||||
if (awake && !mWakeLock.isHeld()) {
|
||||
Log.d(SBMP_TAG, "Acquiring wakelock");
|
||||
mWakeLock.acquire();
|
||||
} else if (!awake && mWakeLock.isHeld()) {
|
||||
Log.d(SBMP_TAG, "Releasing wakelock");
|
||||
mWakeLock.release();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue