Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.activity_main);
  5. MediaPlayer mp = MediaPlayer.create(this, R.raw.music);
  6. Button ImageButton = (Button) findViewById(R.id.button);
  7. ImageButton.setOnTouchListener(new View.OnTouchListener() {
  8. @Override
  9.  
  10. public boolean onTouch(View v, MotionEvent event) {
  11.  
  12. switch(event.getAction()) {
  13. case MotionEvent.ACTION_DOWN:
  14. mp.start;
  15.  
  16. break;
  17. case MotionEvent.ACTION_UP:
  18. mp.stop;
  19.  
  20. break;
  21. }
  22. return false;
  23. }
  24. });
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement