Some time music does not stop android
<p>There is an function which is called on onCreate method of playing music...</p>

<pre><code>    public void playBeep() {
    try {

        if (m.isPlaying()) {
            m.stop();
            m.release();
            m = new MediaPlayer();
        }
        AssetFileDescriptor descriptor = getAssets().openFd("beep.mp3");
        m.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
        descriptor.close();

        m.prepare();
        m.setVolume(1f, 1f);
        m.setLooping(true);
        m.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
   }
</code></pre>

<p>and on onPause method i have written code of stop music so when user leaves activity music should automatically stops...</p>

<pre><code>        @Override
protected void onPause() {
    isBeeping = false;
    if (m != null) {

        if (m.isPlaying()) {
            m.stop();
            m.release();
        }
    }
    super.onPause();
}
</code></pre>

<p>but sometime it is working fine but sometime music does not stop!!! </p>

<p>can anybody suggest me how to stop music when leaving activity :)</p>
