Android MediaPlayer Error (-38, 0) “stop called in state 0”

后端 未结 3 1402
误落风尘
误落风尘 2021-02-13 22:02

I have looked at various different websites looking for a solution for this problem in my code. It is a basic audio player with 3 buttons: play, pause and stop. Play and pause w

3条回答
  •  难免孤独
    2021-02-13 22:39

    I fixed this problem by `mediaPlayer.prepare(); My problem is about live radio streaming and I achieve this problem like below code:

    if (!radioIsOpen) {
                    try {
                        mediaPlayer = new MediaPlayer();
                        mediaPlayer
                                .setDataSource(URL);
                        mediaPlayer.prepare();
                    } catch (Exception e) {
                    }
    
                    mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
    
                        public void onPrepared(MediaPlayer mp) {
                            mediaPlayer.start();
                        }
                    });
                    Toast.makeText(getBaseContext(), "Radio is opening...", 2).show();
                } else {
                    if (mediaPlayer.isPlaying()) {
                        mediaPlayer.stop();
                        mediaPlayer.release();
                        Toast.makeText(getBaseContext(), "Radio is closing...", 2).show();
                    }
                }
    

提交回复
热议问题