Jaya Mayu
Jaya Mayu

Reputation: 17247

Android: Unknown MediaPlayer Warning

I'm trying to get the duration of the media file using mediaplayer and all works fine but I'm getting a warning in he DDMS as below.

10-21 17:30:35.109: W/MediaPlayer(7564): mediaplayer went away with unhandled events

My code goes as below

//mediaPlayer object initiated to get the duration
MediaPlayer mediaPlayer;
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

try {
mediaPlayer.setDataSource(AudioListActivity.this, Uri.parse((db_results.get(position)).toString()));
mediaPlayer.prepare();
mediaPlayer.stop();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
        e.printStackTrace();
} catch (IllegalStateException e) {

e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//getting duration
int durationTime = 0;
@SuppressWarnings("unused")
TextView duration = (TextView) row.findViewById(R.id.textViewDuration);
durationTime = mediaPlayer.getDuration();
mediaPlayer.release();

Can someone help me out. Thanks in advance.

Upvotes: 1

Views: 5465

Answers (2)

Tamir
Tamir

Reputation: 31

add: mediaPlayer.reset(); before mediaPlayer.release();

Upvotes: 3

Sree Rama
Sree Rama

Reputation: 1227

It is better to ignore this warning.

1)comment the line of code MediaPlayer.release(); and notice the logcat;

2)You may need to reset the Mediaplayer object before releasing the mp. mp.reset() after that test it. Because some time this will cause other error like "illegal state exception"

3)If it is concern to you, do the reset it in try/catch and handle the exception.

Upvotes: 1

Related Questions