Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- MediaPlayer mp = MediaPlayer.create(this, R.raw.music);
- Button ImageButton = (Button) findViewById(R.id.button);
- ImageButton.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- switch(event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- mp.start;
- break;
- case MotionEvent.ACTION_UP:
- mp.stop;
- break;
- }
- return false;
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement