Media player start/stop - crash
<p>I want to do that when you press the ImageButton sound is started, and after the next click it is stopped.</p>

<p>Starting and stopping work. But when you press the back button, the program crashes.</p>

<p>Where is the problem?</p>

<p>Code:</p>

<pre><code>public class Sound extends Activity implements OnClickListener {
        public int count = 0;
        MediaPlayer y;  
        ImageButton th;

        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app);
        th = (ImageButton)findViewById(R.id.ibFirst);
        y = MediaPlayer.create(this, R.raw.th);
        th.setOnClickListener(this);
        count = 0;
    }
    public void onClick(View th) {
        if(count == 0){
            y.start();
            count = 1;
        } else {
            y.pause();                
            count = 0;
        }
    }
    @Override
    protected void onDestroy() {
        if(y != null) {
            y.pause();
            y.stop();
            y.release();
            count = 0;
        }
        }


}
</code></pre>

<p>ERRORS:</p>

<p>When i clicked start/stop start/stop 10x :D</p>

<pre><code>3-02 14:21:05.395: W/MediaPlayer(233): info/warning (1, 44)
    03-02 14:21:05.494: I/MediaPlayer(233): Info (1,44)
    03-02 14:22:28.085: E/MediaPlayer(233): pause called in state 128
    03-02 14:22:28.085: E/MediaPlayer(233): error (-38, 0)
    03-02 14:22:28.085: E/MediaPlayer(233): Error (-38,0)
    03-02 14:22:33.455: E/MediaPlayer(233): start called in state 0
    03-02 14:22:33.455: E/MediaPlayer(233): error (-38, 0)
    03-02 14:22:33.455: E/MediaPlayer(233): Error (-38,0)
    03-02 14:22:35.964: W/KeyCharacterMap(233): No keyboard for id 0
    03-02 14:22:35.964: W/KeyCharacterMap(233): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
    03-02 14:22:36.584: E/MediaPlayer(233): pause called in state 0
    03-02 14:22:36.584: E/MediaPlayer(233): error (-38, 0)
    03-02 14:22:36.584: E/MediaPlayer(233): stop called in state 0
    03-02 14:22:36.584: E/MediaPlayer(233): error (-38, 0)
</code></pre>

<p>When I pressed back button.</p>

<pre><code>        03-02 14:22:36.635: D/AndroidRuntime(233): Shutting down VM
        03-02 14:22:36.635: W/dalvikvm(233): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
        03-02 14:22:36.635: E/AndroidRuntime(233): Uncaught handler: thread main exiting due to uncaught exception
        03-02 14:22:36.655: E/AndroidRuntime(233): android.app.SuperNotCalledException: Activity {com.troll.sound/com.troll.sound.Sound} did not call through to super.onDestroy()
        03-02 14:22:36.655: E/AndroidRuntime(233):  at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3458)
        03-02 14:22:36.655: E/AndroidRuntime(233):  at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3487)
        03-02 14:22:36.655: E/AndroidRuntime(233):  at android.app.ActivityThread.access$2800(ActivityThread.java:119)
        03-02 14:22:36.655: E/AndroidRuntime(233):  at 

android.app.ActivityThread$H.handleMessage(ActivityThread.java:1896)
    03-02 14:22:36.655: E/AndroidRuntime(233):  at android.os.Handler.dispatchMessage(Handler.java:99)
    03-02 14:22:36.655: E/AndroidRuntime(233):  at android.os.Looper.loop(Looper.java:123)
    03-02 14:22:36.655: E/AndroidRuntime(233):  at android.app.ActivityThread.main(ActivityThread.java:4363)
    03-02 14:22:36.655: E/AndroidRuntime(233):  at java.lang.reflect.Method.invokeNative(Native Method)
    03-02 14:22:36.655: E/AndroidRuntime(233):  at java.lang.reflect.Method.invoke(Method.java:521)
    03-02 14:22:36.655: E/AndroidRuntime(233):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    03-02 14:22:36.655: E/AndroidRuntime(233):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    03-02 14:22:36.655: E/AndroidRuntime(233):  at dalvik.system.NativeStart.main(Native Method)
    03-02 14:22:36.685: I/dalvikvm(233): threadid=7: reacting to signal 3
    03-02 14:22:36.714: E/dalvikvm(233): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
</code></pre>
