Android change play/pause button icon when clicked
<p>Honestly, I do not know why, but any solution for same problem I have as already on stackoverflow is not working for me 
I am trying to have play/pause buttons switched when clicked, when playing my stream for my radio station. </p>

<p>I do not know what I am doing wrong.</p>

<p>Currently it is separate, because many of my attempts failed. </p>

<p><strong>main.xml</strong> (many call it activity main)</p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/bg"
    android:weightSum="1"&gt;

    &lt;ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/logo"
        android:id="@+id/imageView4" /&gt;

    &lt;Button
        android:id="@+id/play"
        android:layout_margin="10dip"
        android:background="@drawable/play"
        android:layout_width="50dp"
        android:layout_height="50dp" /&gt;

    &lt;Button
        android:id="@+id/stop"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_margin="10dip"
        android:background="@drawable/pause" /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p><strong>MusicAndroidActivity.java</strong></p>

<pre><code>    package clever.radio;

    import java.io.IOException;

    import android.app.Activity;
    import android.graphics.BitmapFactory;
    import android.media.AudioManager;
    import android.media.MediaPlayer;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.webkit.WebView;
    import android.widget.Button;
    import android.widget.Toast;

    import static android.R.attr.id;

    public class MusicAndroidActivity extends Activity {

        static MediaPlayer mPlayer;
        Button buttonPlay;
        Button buttonStop;
        String url = "http://radioclever.stream:8000/stream";
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            buttonPlay = (Button) findViewById(R.id.play);
            buttonPlay.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    mPlayer = new MediaPlayer();
                    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    try {
                        mPlayer.setDataSource(url);
                    } catch (IllegalArgumentException e) {
                        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
                    } catch (SecurityException e) {
                        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
                    } catch (IllegalStateException e) {
                        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        mPlayer.prepare();
                    } catch (IllegalStateException e) {
                        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
                    } catch (IOException e) {
                        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
                    }
                    mPlayer.start();
                }
            });

            buttonStop = (Button) findViewById(R.id.stop);
            buttonStop.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    if(mPlayer!=null &amp;&amp; mPlayer.isPlaying()){
                        mPlayer.stop();
                    }
                }
            });
        }

        protected void onDestroy() {
            super.onDestroy();
            // TODO Auto-generated method stub
            if (mPlayer != null) {
                mPlayer.release();
                mPlayer = null;
            }
        }
    }
</code></pre>

<p><strong>AndroidManifest.xml</strong></p>

<pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="clever.radio"
    android:versionCode="1"
    android:versionName="1.1" &gt;

    &lt;uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="15" /&gt;

    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;

    &lt;application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme" &gt;
        &lt;activity
            android:name=".MusicAndroidActivity" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>