Reputation: 1807
I have the following piece of code.
ex:
if(player1 != null){
if(player1.isPlaying()){ //check if it playing
//other code
}
}
QUESTION 1:
The condition check for null always passes even though the media player as finished playing and i release the player on oncompletion.
//release on completion of the player
player1.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
Log.d(TAG, "Media player has completed playing");
}
});
QUESTION 2:
IF the player HAS finished playing, a check for null
still returns false and it fails as isPlaying
giving an illegalstateexception
.
Upvotes: 1
Views: 2911
Reputation: 22527
Releasing the player doesnt nullify the instance. Add null after release if thats what you want.
player1.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
mp = null;
Log.d(TAG, "Media player has completed playing");
}
});
Upvotes: 3