Advertisement
Abdurrahmaaqil

Untitled

May 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. public class asli extends AppCompatActivity {
  2. Button clk1, clk2;
  3. MediaPlayer mp;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. this.setTitle(" Mad Asli / Mad Thobi'i");
  9. setContentView(R.layout.activity_asli);
  10. clk1 = (Button) findViewById(R.id.playid);
  11. clk2 = (Button) findViewById(R.id.pauseid);
  12.  
  13. mp = MediaPlayer.create(this, R.raw.mad_thobii);
  14. }
  15. public void clkplay(View v){
  16. mp.start();
  17. }
  18. public void clkpause(View v){
  19. mp.pause();
  20. }
  21.  
  22. /*dibawah ini untuk berhenti ketika on backpressed */
  23. @Override
  24. protected void onStop() {
  25. super.onStop();
  26.  
  27. if(mp!=null && mp.isPlaying())
  28. {
  29. mp.stop();
  30. mp.release();
  31. mp = null;
  32. }
  33. }
  34. @Override
  35. protected void onDestroy() {
  36. super.onDestroy();
  37. if(mp!=null && mp.isPlaying())
  38. {
  39. mp.stop();
  40. mp.release();
  41. mp = null;
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement