Android: Mediaplayer stop / start playing raw resource

不想你离开。 提交于 2019-12-07 20:19:27

This block of code:

if (mp!=null){
    mp.reset();
    mp.release();
}

will never be executed. mp can only be null at this point, as it is in the else block of an if (mp != null) test. This suggests that there is a flaw in your thinking regarding the use of this method.

If a sound has played through and you press the button, then this code will execute:

mp.release();
mp = null;

Since mp was not null, the else block doesn't execute and no new sound is played. When the button is pressed a second time, mp is now null and the else block gets executed, creating a new MediaPlayer and playing the sound.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!