Merge branch 'issue-497' into develop
This commit is contained in:
commit
8e0595ee66
@ -11,6 +11,12 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
// Compared to the original version, this class been slightly modified so
|
||||||
|
// that any acquired WakeLocks are only held while the MediaPlayer is
|
||||||
|
// playing (see the stayAwake method for more details).
|
||||||
|
|
||||||
|
|
||||||
package com.aocate.media;
|
package com.aocate.media;
|
||||||
|
|
||||||
@ -40,6 +46,8 @@ import com.aocate.presto.service.IOnSeekCompleteListenerCallback_0_8;
|
|||||||
import com.aocate.presto.service.IOnSpeedAdjustmentAvailableChangedListenerCallback_0_8;
|
import com.aocate.presto.service.IOnSpeedAdjustmentAvailableChangedListenerCallback_0_8;
|
||||||
import com.aocate.presto.service.IPlayMedia_0_8;
|
import com.aocate.presto.service.IPlayMedia_0_8;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.BuildConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for connecting to remote speed-altering, media playing Service
|
* Class for connecting to remote speed-altering, media playing Service
|
||||||
* Note that there is unusually high coupling between MediaPlayer and this
|
* Note that there is unusually high coupling between MediaPlayer and this
|
||||||
@ -206,6 +214,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
|||||||
void error(int what, int extra) {
|
void error(int what, int extra) {
|
||||||
owningMediaPlayer.lock.lock();
|
owningMediaPlayer.lock.lock();
|
||||||
Log.e(SBMP_TAG, "error(" + what + ", " + extra + ")");
|
Log.e(SBMP_TAG, "error(" + what + ", " + extra + ")");
|
||||||
|
stayAwake(false);
|
||||||
try {
|
try {
|
||||||
if (!this.isErroring) {
|
if (!this.isErroring) {
|
||||||
this.isErroring = true;
|
this.isErroring = true;
|
||||||
@ -478,6 +487,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
ServiceBackedMediaPlayer.this.error(MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
|
ServiceBackedMediaPlayer.this.error(MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
|
||||||
}
|
}
|
||||||
|
stayAwake(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -581,6 +591,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
ServiceBackedMediaPlayer.this.error(MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
|
ServiceBackedMediaPlayer.this.error(MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
|
||||||
}
|
}
|
||||||
|
stayAwake(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -870,12 +881,28 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
|||||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
// Since mode can't be changed on the fly, we have to allocate a new one
|
// 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 = pm.newWakeLock(mode, this.getClass().getName());
|
||||||
|
this.mWakeLock.setReferenceCounted(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mWakeLock.acquire();
|
this.mWakeLock.acquire();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the state of the WakeLock if it has been acquired.
|
||||||
|
* If no WakeLock has been acquired with setWakeMode, this method does nothing.
|
||||||
|
* */
|
||||||
|
private void stayAwake(boolean awake) {
|
||||||
|
if (BuildConfig.DEBUG) Log.d(SBMP_TAG, "stayAwake(" + awake + ")");
|
||||||
|
if (mWakeLock != null) {
|
||||||
|
if (awake && !mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.acquire();
|
||||||
|
} else if (!awake && mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private IOnBufferingUpdateListenerCallback_0_8.Stub mOnBufferingUpdateCallback = null;
|
private IOnBufferingUpdateListenerCallback_0_8.Stub mOnBufferingUpdateCallback = null;
|
||||||
private void setOnBufferingUpdateCallback(IPlayMedia_0_8 iface) {
|
private void setOnBufferingUpdateCallback(IPlayMedia_0_8 iface) {
|
||||||
try {
|
try {
|
||||||
@ -913,6 +940,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
|||||||
public void onCompletion() throws RemoteException {
|
public void onCompletion() throws RemoteException {
|
||||||
owningMediaPlayer.lock.lock();
|
owningMediaPlayer.lock.lock();
|
||||||
Log.d(SBMP_TAG, "onCompletionListener being called");
|
Log.d(SBMP_TAG, "onCompletionListener being called");
|
||||||
|
stayAwake(false);
|
||||||
try {
|
try {
|
||||||
if (owningMediaPlayer.onCompletionListener != null) {
|
if (owningMediaPlayer.onCompletionListener != null) {
|
||||||
owningMediaPlayer.onCompletionListener.onCompletion(owningMediaPlayer);
|
owningMediaPlayer.onCompletionListener.onCompletion(owningMediaPlayer);
|
||||||
@ -940,7 +968,8 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
|||||||
this.mOnErrorCallback = new IOnErrorListenerCallback_0_8.Stub() {
|
this.mOnErrorCallback = new IOnErrorListenerCallback_0_8.Stub() {
|
||||||
public boolean onError(int what, int extra) throws RemoteException {
|
public boolean onError(int what, int extra) throws RemoteException {
|
||||||
owningMediaPlayer.lock.lock();
|
owningMediaPlayer.lock.lock();
|
||||||
try {
|
stayAwake(false);
|
||||||
|
try {
|
||||||
if (owningMediaPlayer.onErrorListener != null) {
|
if (owningMediaPlayer.onErrorListener != null) {
|
||||||
return owningMediaPlayer.onErrorListener.onError(owningMediaPlayer, what, extra);
|
return owningMediaPlayer.onErrorListener.onError(owningMediaPlayer, what, extra);
|
||||||
}
|
}
|
||||||
@ -1146,6 +1175,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
ServiceBackedMediaPlayer.this.error(MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
|
ServiceBackedMediaPlayer.this.error(MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
|
||||||
}
|
}
|
||||||
|
stayAwake(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1166,5 +1196,6 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
ServiceBackedMediaPlayer.this.error(MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
|
ServiceBackedMediaPlayer.this.error(MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
|
||||||
}
|
}
|
||||||
|
stayAwake(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user