Skip to content

Commit

Permalink
Do not prepare if release has already been called
Browse files Browse the repository at this point in the history
  • Loading branch information
protyposis committed Oct 3, 2016
1 parent a6a1d36 commit 8c511fe
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,20 @@ public boolean handleMessage(Message msg) {
@Override
public void run() {
try {
mCurrentState = STATE_PREPARING;

mPlayer.setDataSource(mSource);

if(mPlayer == null) {
// player has been release while the data source was set
return;
}

// Async prepare spawns another thread inside this thread which really isn't
// necessary; we call this method anyway because of the events it triggers
// when it fails, and to stay in sync which the Android VideoView that does
// the same.
mPlayer.prepareAsync();
mCurrentState = STATE_PREPARING;

Log.d(TAG, "video opened");
} catch (IOException e) {
Expand Down Expand Up @@ -270,6 +276,8 @@ private void release() {
mPlayer.release();
mPlayer = null;
}
mCurrentState = STATE_IDLE;
mTargetState = STATE_IDLE;
}

public void setOnPreparedListener(MediaPlayer.OnPreparedListener l) {
Expand Down

0 comments on commit 8c511fe

Please sign in to comment.