play music imageButton android java code code example
Example: android play music on button click
public class MainActivity extends AppCompatActivity{
Button bt;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = (Button)findViewById(R.id.clickme);
final MediaPlayer mp = MediaPlayer.create(this, R.raw.sample);
bt.setOnClickListener(new View.OnClickListener(){
@Overridepublic void onClick(View view){
np.start();
}
}
}
}