How to stop the song on the ImageButton button when it is pressed again?
My Java code is:
package com.example.killerlii.nedaibogzafeilit; import android.graphics.Bitmap; import android.graphics.Typeface; import android.media.MediaPlayer; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.FocusFinder; import android.view.View; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.ScrollView; import android.widget.TextView; public class main extends AppCompatActivity { TextView t; ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setIcon(R.drawable.ic_logo); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); t = (TextView) findViewById(R.id.nazvanie); Typeface meCustomFont1 = Typeface.createFromAsset(getAssets(), "fonts/LegionaryBold.otf"); t.setTypeface(meCustomFont1); t = (TextView) findViewById(R.id.predpisanie); Typeface meCustomFont2 = Typeface.createFromAsset(getAssets(), "fonts/LegionaryItalic.otf"); t.setTypeface(meCustomFont2); t = (TextView) findViewById(R.id.opisan); Typeface meCustomFont3 = Typeface.createFromAsset(getAssets(), "fonts/Legionary.otf"); t.setTypeface(meCustomFont3); RelativeLayout mainpage = (RelativeLayout) findViewById(R.id.mainpage); ScrollView Opisanie = (ScrollView) findViewById(R.id.Opisanie); final ImageView imageView = (ImageView) findViewById(R.id.ImageView); final TextView nazvanie = (TextView) findViewById(R.id.nazvanie); final TextView predpisanie = (TextView) findViewById(R.id.predpisanie); final TextView opisan = (TextView) findViewById(R.id.opisan); ScrollView Perecheslenie = (ScrollView) findViewById(R.id.Perecheslenie); final ImageButton imageButton = (ImageButton) findViewById(R.id.imageButton); final ImageButton imageButton2 = (ImageButton) findViewById(R.id.imageButton2); final ImageButton imageButton3 = (ImageButton) findViewById(R.id.imageButton3); final ImageButton imageButton4 = (ImageButton) findViewById(R.id.imageButton4); final ImageButton imageButton5 = (ImageButton) findViewById(R.id.imageButton5); final ImageButton imageButton6 = (ImageButton) findViewById(R.id.imageButton6); final ImageButton imageButton7 = (ImageButton) findViewById(R.id.imageButton7); final ImageButton imageButton8 = (ImageButton) findViewById(R.id.imageButton8); final ImageButton imageButton9 = (ImageButton) findViewById(R.id.imageButton9); final ImageButton imageButton10 = (ImageButton) findViewById(R.id.imageButton10); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MediaPlayer ring= MediaPlayer.create(main.this,R.raw.firsts); ring.start(); nazvanie.setText(getResources().getString(R.string.imageButton1)); predpisanie.setText(getResources().getString(R.string.imageButton1_1)); opisan.setText(getResources().getText(R.string.imageButton1_2)); image = (ImageView)findViewById(R.id.imageView); image.setImageResource(R.drawable.ic_launcher); } }); } }