extends MediaPlayer : MediaPlayer « Media « Android






extends MediaPlayer

   
//package com.hrw.musicplayer.utils;

import java.io.IOException;

import android.media.MediaPlayer;

 class MediaPlayerUtil extends MediaPlayer {
  private static MediaPlayerUtil INSTANCE = null;

  private boolean isPause = false;

  public boolean isPause() {
    return isPause;
  }

  public void setPause(boolean isPause) {
    this.isPause = isPause;
  }

  private MediaPlayerUtil() {

  }

  public static MediaPlayerUtil getInstance(
      OnCompletionListener onCompeletionListener) {
    if (null == INSTANCE) {
      INSTANCE = new MediaPlayerUtil();
    }
    INSTANCE.setOnCompletionListener(onCompeletionListener);
    return INSTANCE;
  }

  @Override
  public void reset() {
    isPause = false;
    super.reset();
  }

  public void play() throws IllegalStateException, IOException {
    if (!isPause) {
      super.prepare();
    }
    super.start();
  }

  @Override
  public void stop() throws IllegalStateException {
    isPause = false;
    super.stop();
  }

  @Override
  public void pause() throws IllegalStateException {
    isPause = true;
    super.pause();
  }

  public void previousOrNext() throws IllegalStateException, IOException {
    isPause = false;
    play();

  }
}

   
    
    
  








Related examples in the same category

1.Using MediaPlayer to play MP3 file
2.MediaPlayer and Text to Speech
3.Load mp3 file with MediaPlayer and play
4.Call prepare for MediaPlayer before starting
5.Set URL data source for MediaPlayer
6.Audio MediaPlayer Demo
7.Using MediaPlayer to play Video and Audio
8.MediaPlayer create and start
9.Multi PlayMixer
10.Play movie.m4v file
11.Using Service to play media file