Code example for MediaPlayer: Playing audio and video

Methods: start

0
 
    private static final long VIBRATE_DURATION = 200L;
 
    private void playBeepSoundAndVibrate() { 
        if (playBeep && mediaPlayer != null) {
            mediaPlayer.start();
        } 
        if (vibrate) {
            Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
            vibrator.vibrate(VIBRATE_DURATION);
        } 
    } 
 
    /** 
     * When the beep has finished playing, rewind to queue up another one. 
     */ 
    private final OnCompletionListener beepListener = new OnCompletionListener() {
        public void onCompletion(MediaPlayer mediaPlayer) { 
            mediaPlayer.seekTo(0); 
        } 
    };