SHARE
TWEET

HappyPlace MyMediaPlayer

Allen_L Oct 30th, 2013 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import android.content.Context;
  2. import android.media.MediaPlayer;
  3. import android.media.MediaPlayer.OnCompletionListener;
  4.  
  5. public class MyMediaPlayer {
  6.         // use Media player for sound instead of SoundPool for OnCompletion Listener
  7.         private static MediaPlayer mediaPlayer;
  8.  
  9.         public static void mediaPlaySound(Context context) {
  10.                 mediaPlayer = MediaPlayer.create(context, R.raw.happyplace);
  11.                 mediaPlayer.start();
  12.                 mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
  13.  
  14.                         @Override
  15.                         public void onCompletion(MediaPlayer mp) {
  16.                                 MainActivity.sadPictureReturn();
  17.                                 mediaPlayer.release();// finished with sound
  18.                         }
  19.                 });
  20.         }
  21. }
RAW Paste Data
Top