// playback public Playback(SurfaceView surfaceview, int playerMode) { mmediaplayer = new MediaPlayer(); msurfaceholder = surfaceview.getHolder(); msurfaceholder.addCallback(this); // msurfaceholder.setFixedSize(surfaceview.getWidth(), // surfaceview.getHeight()); msurfaceholder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mmediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mmediaplayer.setDisplay(msurfaceholder); mmediaplayer.setOnErrorListener(errListener); mmediaplayer.setOnPreparedListener(preListener); mmediaplayer.setOnCompletionListener(completeListener); mmediaplayer.setOnSeekCompleteListener(seekListener); mPlayStatus = VideoConst.PLAY_STATUS_UNKNOW; if (playerMode == VideoConst.PLAYER_MODE_MMP) { videopl = PlayList.getPlayList(); mcurPath = videopl.getCurrentPath(Const.FILTER_VIDEO); } mplayerMode = playerMode; pb = this; }
public void onCompletion(MediaPlayer arg0) { // TODO Auto-generated method stub MmpTool.LOG_DBG("play compeletion!"); if (mmediaplayer != null) { saveProgress(0); if (videopl.getShuffleMode(Const.FILTER_VIDEO) == Const.SHUFFLE_ON || videopl.getRepeatMode(Const.FILTER_VIDEO) == Const.REPEAT_NONE) { if (videopl.getCurrentIndex(Const.FILTER_VIDEO) >= ((videopl.getFileNum(Const.FILTER_VIDEO) - 1))) { try { isEnd = true; mmediaplayer.stop(); mPlayStatus = VideoConst.PLAY_STATUS_END; throw new Exception("End of PlayList!!!"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } try { autoNext(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if (mOnPBCompleteListener != null) { mOnPBCompleteListener.onComplete(pb); } } }
/** manual preview */ public void manualPrev() throws IllegalStateException { if (mmediaplayer != null) { if (mplayerMode == VideoConst.PLAYER_MODE_HTTP) { throw new IllegalStateException("Can't do Prev!!!"); } if (videopl.getShuffleMode(Const.FILTER_VIDEO) == Const.SHUFFLE_ON || videopl.getRepeatMode(Const.FILTER_VIDEO) == Const.REPEAT_NONE) { if (videopl.getCurrentIndex(Const.FILTER_VIDEO) == 0) { throw new IllegalStateException("head of PlayList!!!"); } } saveProgress(getProgress()); if (mPlayStatus != VideoConst.PLAY_STATUS_STOPPED) { try { mmediaplayer.stop(); } catch (IllegalStateException e) { e.printStackTrace(); throw new IllegalStateException(e); } mPlayStatus = VideoConst.PLAY_STATUS_STOPPED; } mcurPath = videopl.getNext(Const.FILTER_VIDEO, Const.MANUALPRE); if (mcurPath == null) { MmpTool.LOG_DBG("End of PlayList!"); stop(); } MmpTool.LOG_DBG(mcurPath); mmediaplayer.reset(); mPlayStatus = VideoConst.PLAY_STATUS_END; try { setDataSource(mcurPath); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); throw new IllegalStateException(e); } try { play(); } catch (IllegalStateException e) { e.printStackTrace(); throw new IllegalStateException(e); } } }
private int getSavedProgress() { if (previewMode == true) { return 0; } else { vidman = VideoManager.getInstance(); String path = videopl.getCurrentPath(Const.FILTER_VIDEO); return vidman.getFileInfo().getSavedProgress(path); } }
private void saveProgress(int progress) { if (previewMode == true) { return; } else { vidman = VideoManager.getInstance(); String path = videopl.getCurrentPath(Const.FILTER_VIDEO); String info = "progress = " + Integer.toString(progress); MmpTool.LOG_DBG(info); if (progress > 0 && progress < getDuration()) { vidman.getFileInfo().saveProgress(path, progress); } else { vidman.getFileInfo().saveProgress(path, 0); } } }
private void autoNext() { if (mmediaplayer != null) { if (mplayerMode == VideoConst.PLAYER_MODE_HTTP) { MmpTool.LOG_ERROR("This player mode can't do next!"); throw new IllegalStateException("Can't do Next!!!"); } if (mPlayStatus != VideoConst.PLAY_STATUS_STOPPED) { mmediaplayer.stop(); mPlayStatus = VideoConst.PLAY_STATUS_STOPPED; } mcurPath = videopl.getNext(Const.FILTER_VIDEO, Const.AUTOPLAY); mmediaplayer.reset(); mPlayStatus = VideoConst.PLAY_STATUS_END; try { setDataSource(mcurPath); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } try { play(); } catch (IllegalStateException e) { e.printStackTrace(); } } }