I am using the Android class MediaPlayerto play some remote resources. I would like the user to be able to reuse MediaPlayerto open some content, and then change it to play another, without having to recreate MediaPlayer.
So, I wrote a method for opening a resource, which first of all resets MediaPlayer, so that I can send it to the standby state. After that, I set a new URI, and I call the preparation method. This happens quite often, one way or another, that the method setDataSourcefreezes for many seconds and even 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? Thank!
source
share