Search code examples
androidaudiomedia-player

Android Media Player Restart Audio After Calling Stop


I'm able to stream audio and stop it without any problem, but when I try to start it again after stop, it doesn't start and I get an IllegalState exception.

Here is what I'm doing:

Start Playing

mediaPlayer.setDataSource(PATH);
mediaPlayer.prepare();
mediaPlayer.start();

Stop Playing

mediaPlayer.stop

Now, if I want to start playing again the same media, what will I have to do?

*PATH is the URL of a continuous running radio station.


Solution

  • Add this:

    mp.reset();
    mp.setDataSource(MEDIA_PATH);
    mp.prepare();
    mp.start();