Android: Pause Streaming Audio on MediaPlayer
<p>I have this method to play an audio file with a button:</p>

<pre><code>final MediaPlayer mediaplayer = MediaPlayer.create(
                    this,
                    Uri.parse("android.resource://" + getPackageName() + "/"
                            + R.raw.inro));
            mediaplayer.setOnPreparedListener(new OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    if (mediaplayer.isPlaying()) {
                        mediaplayer.pause();
                    } else {
                        mediaplayer.start();
                    }
                }
            });
</code></pre>

<p>What I'm trying to do is, when the audio is playing and the user clicks the button again, the audio wil pause, but when he clicks it again the audio will resume.</p>

<p>Can anybody help me with that? Thank you</p>

<p><strong>UPDATED:</strong></p>

<pre><code>@Override
    public void onClick(View v) {

        switch (v.getId()) {
        case R.id.btn_nav_back:
            WWHApplication.getMapActivityIntance().getVideoLocationDB();
            WWHApplication.getMapActivityIntance().initLocations();
            if (category == 'f') {
                if (WWHApplication.getFavoritesListActivityIntance() != null)
                    WWHApplication.getFavoritesListActivityIntance()
                            .loadListView();
            }
            finish();
            break;
        case R.id.btn_tool_audio:
            final MediaPlayer mediaplayer = MediaPlayer.create(this,
                    Uri.parse("android.resource://" + getPackageName() + "/"
                            + R.raw.inro));     
                    if (mediaplayer.isPlaying()) {
                        mediaplayer.pause();
                    } else {
                        mediaplayer.start();
                    }

            break;
</code></pre>
