step 1;
activity_main.xml
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"> <Button
android:id="@+id/play"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/image"/> </LinearLayout>
step 2:
MainActivity.javapublic class MainActivity extends AppCompatActivity { MediaPlayer mPlayer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button)findViewById(R.id.play); button.setOnClickListener(new View.OnClickListener() { @Overridepublic void onClick(View v) { if (mPlayer != null) { mPlayer.stop(); mPlayer.reset(); } mPlayer = MediaPlayer.create(MainActivity.this, R.raw.song); mPlayer.start(); } }); }}step 3:res/raw/song.mp3>>>>>>> user songstep 4:res/drawable/image.pnd>>>>>> user image