Hi! I'm using the Android's MediaPlayer class to play some remote resources. I would like the user to be able to reuse the MediaPlayer to open some content and then change it to play another one without having to recreate the MediaPlayer.
So, I wrote a method to open a resource which, first of all, resets the MediaPlayer so that I can send it to the idle state. After that, I set the new URI and I call the prepare method. It happens quite often, anyway, that the method setDataSource hangs, for many seconds and even for minutes. This is the code:
mediaPlayer.reset();
mediaPlayer.setDataSource(this, Uri.parse(uri));
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.prepare();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Any idea why the method should hang for many seconds after setDataSource and before the setDisplay method? Thanks!