Thursday, March 28, 2013

Why is MediaPlayer calling IllegalStateException when I call release()?


I have an Activity in which there's a MediaPlayer that, after about 150 plays, puts up a system message saying "Video couldn't be played". A force restart of the app resets this problem for another 150 plays.


I'm assuming that this is a memory leak of some kind, though I'm entirely unclear as to what would be leaking, and also the simptoms don't align with how much memory Android allots my app. The video is about 3mb, so, if I'm leaking that much at every play the implication would be that my app has access to 450mb of memory which we know isn't true.


In any event, I'm trying to see if I can manually release the video somehow, but I'm getting an IllegalStateException when I call release on the MediaPlayer that is passed into my onComplete callback.


My code looks like this:



VideoView vv = (VideoView)findViewById(R.id.movie);
Uri videoURI = Uri.parse("android.resource://" + getPackageName() + "/raw/video_in" );
vv.setVideoURI(videoURI);
vv.start();
vv.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Intent i = new Intent(getPackageName() + ".SCENE_2");
startActivity(i);
mp.stop();
mp.release();//here the exception is raised
finish();
}
});


The documentation seems to imply that there's no state in which you can't call release on a MediaPlayer, so, I'm stumped. I'm in JellyBean, in case that makes any difference.



.

stackoverflow.com

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...