Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Ability to trigger implementation switch
Browse files Browse the repository at this point in the history
  • Loading branch information
mfietz committed Mar 24, 2016
1 parent 4f23aa2 commit a134f48
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions library/src/main/java/org/antennapod/audio/MediaPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ public void fallback() {
setupMpi(this.mpi.mContext);
}

protected void checkMpi() {
if(this.invalidServiceConnectionConfiguration()) {
this.setupMpi(this.mpi.mContext);
}
}

private void setupMpi(final Context context) {
lock.lock();
try {
Expand Down Expand Up @@ -592,15 +598,13 @@ private void switchMediaPlayerImpl(AbstractAudioPlayer from, AbstractAudioPlayer
// on(Pitch|Speed)AdjustmentAvailableChanged
if ((to.canSetPitch() != this.pitchAdjustmentAvailable)
&& (this.onPitchAdjustmentAvailableChangedListener != null)) {
this.onPitchAdjustmentAvailableChangedListener
.onPitchAdjustmentAvailableChanged(this, to
.canSetPitch());
this.onPitchAdjustmentAvailableChangedListener.onPitchAdjustmentAvailableChanged(
this, to.canSetPitch());
}
if ((to.canSetSpeed() != this.speedAdjustmentAvailable)
&& (this.onSpeedAdjustmentAvailableChangedListener != null)) {
this.onSpeedAdjustmentAvailableChangedListener
.onSpeedAdjustmentAvailableChanged(this, to
.canSetSpeed());
this.onSpeedAdjustmentAvailableChangedListener.onSpeedAdjustmentAvailableChanged(
this, to.canSetSpeed());
}
Log.d(MP_TAG, "switchMediaPlayerImpl() " + this.state.toString());
} finally {
Expand Down Expand Up @@ -838,9 +842,7 @@ public void openPrestoMarketIntent() {
public void pause() {
lock.lock();
try {
if (invalidServiceConnectionConfiguration()) {
setupMpi(this.mpi.mContext);
}
checkMpi();
this.state = State.PAUSED;
this.mpi.pause();
} finally {
Expand All @@ -858,9 +860,7 @@ public void prepare() throws IllegalStateException, IOException {
Log.d(MP_TAG, "prepare() using " + ((this.mpi == null) ? "null (this shouldn't happen)" : this.mpi.getClass().toString()) + " state " + this.state.toString());
Log.d(MP_TAG, "onPreparedListener is: " + ((this.onPreparedListener == null) ? "null" : "non-null"));
Log.d(MP_TAG, "preparedListener is: " + ((this.preparedListener == null) ? "null" : "non-null"));
if (invalidServiceConnectionConfiguration()) {
setupMpi(this.mpi.mContext);
}
checkMpi();
this.mpi.prepare();
this.state = State.PREPARED;
Log.d(MP_TAG, "prepare() finished");
Expand All @@ -877,9 +877,7 @@ public void prepareAsync() {
lock.lock();
try {
Log.d(MP_TAG, "prepareAsync()");
if (invalidServiceConnectionConfiguration()) {
setupMpi(this.mpi.mContext);
}
checkMpi();
this.state = State.PREPARING;
this.mpi.prepareAsync();
} finally {
Expand Down Expand Up @@ -972,9 +970,7 @@ public void setDataSource(Context context, Uri uri)
lock.lock();
try {
Log.d(MP_TAG, "In setDataSource(context, " + uri.toString() + "), using " + this.mpi.getClass().toString());
if (invalidServiceConnectionConfiguration()) {
setupMpi(this.mpi.mContext);
}
checkMpi();
this.state = State.INITIALIZED;
this.stringDataSource = null;
this.uriDataSource = uri;
Expand All @@ -993,9 +989,7 @@ public void setDataSource(String path) throws IllegalArgumentException,
lock.lock();
try {
Log.d(MP_TAG, "In setDataSource(context, " + path + ")");
if (invalidServiceConnectionConfiguration()) {
setupMpi(this.mpi.mContext);
}
checkMpi();
this.state = State.INITIALIZED;
this.stringDataSource = path;
this.uriDataSource = null;
Expand Down Expand Up @@ -1255,9 +1249,7 @@ public void start() {
lock.lock();
try {
Log.d(MP_TAG, "start()");
if (invalidServiceConnectionConfiguration()) {
setupMpi(this.mpi.mContext);
}
checkMpi();
this.state = State.STARTED;
this.mpi.start();
} finally {
Expand All @@ -1272,9 +1264,7 @@ public void start() {
public void stop() {
lock.lock();
try {
if (invalidServiceConnectionConfiguration()) {
setupMpi(this.mpi.mContext);
}
checkMpi();
this.state = State.STOPPED;
this.mpi.stop();
} finally {
Expand Down

0 comments on commit a134f48

Please sign in to comment.