0

I am streaming using MediaPlayer the problem is its not resuming when the user gets back to the switch case it just play from the start every time the user switch back, Thanks i really need your guys help :)

@Override
public void onCheckedChanged(RadioGroup rg, int i) {
    int rIds = rGroup.getCheckedRadioButtonId();

    switch (rIds){
        case R.id.btn:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
        case R.id.btn1:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
        case R.id.btn2:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
        case R.id.btn3:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
        case R.id.btn4:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
        case R.id.btn5:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
        case R.id.btn6:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
        case R.id.btn7:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
        case R.id.btn8:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
        case R.id.btn9:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
        case R.id.btn10:
            if(mPlayer.isPlaying()) {
                loadProgress();
                mPlayer.reset();
                streamMp3(CLASS.staticMethodforURL);
            }else{
                loadProgress();
                streamMp3(CLASS.staticMethodforURL);
            }
            break;
    }
}

private void streamMp3(String u) {
    try {
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mPlayer.setDataSource(u);
        mPlayer.setLooping(true);
        mPlayer.prepareAsync();
        mPlayer.setOnPreparedListener(this);
    } catch (Exception e) {

    }
}
  • Possible duplicate of [Android 2.2 MediaPlayer is working fine with one SHOUTcast URL but not with the other one](https://stackoverflow.com/questions/8681550/android-2-2-mediaplayer-is-working-fine-with-one-shoutcast-url-but-not-with-the) – Yandry Pozo Jun 04 '17 at 03:23

2 Answers2

0

instead of using reset() method use pause()

GGWP
  • 1,111
  • 2
  • 12
  • 24
0

mPlayer.reset(); is reset your media player which means the player starts again.use mPlayer.stop(); for stop the media player or mPlayer.pause(); to pause the player