Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. private int playSound(int file) {
  2.  
  3. int duration = 1000;
  4. sound = new MediaPlayer();
  5.  
  6. AssetFileDescriptor fd = getResources().openRawResourceFd(file);
  7. try {
  8. sound.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
  9. sound.prepare();
  10. sound.start();
  11.  
  12. sound.setOnCompletionListener(new OnCompletionListener() {
  13. @Override
  14. public void onCompletion(MediaPlayer mp) {
  15. // Do the work after completion of audio
  16. Toast.makeText(GameActivity.this, "good", Toast.LENGTH_SHORT).show();
  17. mp.release();
  18. }
  19. });
  20. duration = sound.getDuration();
  21.  
  22. } catch (IllegalArgumentException e) {
  23. // TODO Auto-generated catch block
  24. e.printStackTrace();
  25. } catch (IllegalStateException e) {
  26. // TODO Auto-generated catch block
  27. e.printStackTrace();
  28. } catch (IOException e) {
  29. // TODO Auto-generated catch block
  30. e.printStackTrace();
  31. }
  32.  
  33. return duration;
  34. }
  35.  
  36. media.setVolume(0,0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement