Mega Code Archive

 
Categories / Android / Media
 

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();   } }