private void release(boolean all) { if (mPlayer != null) { if (mListener != null) mListener.onCloseStart(); mPlayer.reset(); mInitialized = false; mPrepared = false; mVideoSizeKnown = false; if (mListener != null) mListener.onCloseComplete(); } if (all) { mListener = null; mUri = null; } }
public boolean initialize( Uri filePath, String displayName, boolean saveUri, float startPos, VPlayerListener listener, int parentId, boolean isHWCodec) { if (mPlayer == null) vplayerInit(isHWCodec); mTitle = displayName; mListener = listener; mOldUri = mUri; mUri = filePath; mSeekTo = startPos; mMediaId = -1; mLastAudioTrack = -1; mLastSubTrackId = -1; mLastSubTrack = ""; setMediaTrack(); Log.i("%s ==> %s, %s, %s, %s", mOldUri, mUri, mInitialized, mPrepared, mVideoSizeKnown); mFromNotification = mInitialized && mUri != null && mUri.equals(mOldUri); mListener.onOpenStart(); if (!mFromNotification) openVideo(); else openSuccess(); return mInitialized; }
@Override public boolean onInfo(MediaPlayer arg0, int arg1, int arg2) { switch (arg1) { case MediaPlayer.MEDIA_INFO_BUFFERING_START: if (mListener != null) mListener.onBufferStart(); else mPlayer.pause(); break; case MediaPlayer.MEDIA_INFO_BUFFERING_END: if (mListener != null) mListener.onBufferComplete(); else mPlayer.start(); break; case MediaPlayer.MEDIA_INFO_DOWNLOAD_RATE_CHANGED: if (mListener != null) mListener.onDownloadRateChanged(arg2); break; } return true; }
@Override public void onCompletion(MediaPlayer arg0) { if (mListener != null) { mListener.onPlaybackComplete(); } else { release(true); } }
private void openSuccess() { mInitialized = true; if (!mFromNotification && mSeekTo > 0 && mSeekTo < 1) seekTo(mSeekTo); mSeekTo = -1; mListener.onOpenSuccess(); if (!mFromNotification) { setSubEncoding(VP.DEFAULT_SUB_ENCODING); if (mUri != null) mSubPaths = getSubFiles(mUri.getPath()); if (mSubPaths != null) setSubPath(FileUtils.getCanonical(new File(mSubPaths[0]))); setSubShown(VP.DEFAULT_SUB_SHOWN); } }
@Override public void onTimedTextUpdate(byte[] pixels, int width, int height) { if (mListener != null) mListener.onSubChanged(pixels, width, height); }
@Override public void onTimedText(String text) { if (mListener != null) mListener.onSubChanged(text); }
@Override public boolean onError(MediaPlayer arg0, int arg1, int arg2) { mListener.onOpenFailed(); return true; }
@Override public void onVideoSizeChanged(MediaPlayer arg0, int arg1, int arg2) { mVideoSizeKnown = true; if (mListener != null) mListener.onVideoSizeChanged(arg1, arg2); }