Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing song one after another causes MP3Extractor error

@Override
public void onCreate(Bundle savedInstanceState) {
...
        mMediaPlayer = new MediaPlayer();

        mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mediaPlayer) {
                playAudio(getNextAudioFile());
            }
        });
..
}

@Override
protected void onDestroy() {
    super.onDestroy();
    if(mMediaPlayer != null) {
        mMediaPlayer.release();
        mMediaPlayer = null;
    }
}
    private boolean playAudio(String file) {
        if(file.isEmpty()) {
            return true;
        }

        if(mMediaPlayer.isPlaying()) {          
            mMediaPlayer.stop();
        }
    mMediaPlayer.reset();

        mAudioFile = new File(mBaseAudioDir, file);
        if(mAudioFile.canRead()) {
            try {
            mMediaPlayer.setDataSource(mAudioFile.getPath());
                mMediaPlayer.prepare();
            } catch (IllegalArgumentException e) {
                return false;
            } catch (IllegalStateException e) {
                return false;
            } catch (IOException e) {
                return false;
            }
            mMediaPlayer.start();
            return true;
        } else {
            return false;
        }
    }

It works, but after song ends I have this error message in the log:

03-13 12:52:05.101: ERROR/MP3Extractor(34): Unable to resync. Signalling end of stream. 03-13 13:16:59.585: INFO/StagefrightPlayer(34): setDataSource('/mnt/sdcard/Audio/sound.mp3')

like image 599
xXx_CodeMonkey_xXx Avatar asked Nov 05 '22 01:11

xXx_CodeMonkey_xXx


1 Answers

You should really not just have empty catch blocks, you may be getting an explanation to that error but your just ignoring it try this:

     try {
        mMediaPlayer.setDataSource(mAudioFile.getPath());
            mMediaPlayer.prepare();
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "mMediaPlayer IllegalArgumentException " ,e);
            return false;
        } catch (IOException e) {
            Log.e(TAG, "mMediaPlayer IOException" ,e);
            return false;
        }
like image 116
Blundell Avatar answered Nov 09 '22 14:11

Blundell