private void vplayerInit(boolean isHWCodec) { mPlayer = new MediaPlayer(PlayerService.this.getApplicationContext(), isHWCodec); mPlayer.setOnHWRenderFailedListener( new OnHWRenderFailedListener() { @Override public void onFailed() { if (mListener != null) mListener.onHWRenderFailed(); } }); mPlayer.setOnBufferingUpdateListener(PlayerService.this); mPlayer.setOnCompletionListener(PlayerService.this); mPlayer.setOnPreparedListener(PlayerService.this); mPlayer.setOnVideoSizeChangedListener(PlayerService.this); mPlayer.setOnErrorListener(PlayerService.this); mPlayer.setOnInfoListener(PlayerService.this); }
private void openVideo() { if (mUri == null || mSurfaceHolder == null || !Vitamio.isInitialized(mContext)) return; Intent i = new Intent("com.android.music.musicservicecommand"); i.putExtra("command", "pause"); mContext.sendBroadcast(i); release(false); try { mDuration = -1; mCurrentBufferPercentage = 0; mMediaPlayer = new MediaPlayer(mContext); mMediaPlayer.setOnPreparedListener(mPreparedListener); mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener); mMediaPlayer.setOnCompletionListener(mCompletionListener); mMediaPlayer.setOnErrorListener(mErrorListener); mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener); mMediaPlayer.setOnInfoListener(mInfoListener); mMediaPlayer.setOnSeekCompleteListener(mSeekCompleteListener); mMediaPlayer.setOnTimedTextListener(mTimedTextListener); mMediaPlayer.setDataSource(mContext, mUri); mMediaPlayer.setDisplay(mSurfaceHolder); mMediaPlayer.setScreenOnWhilePlaying(true); mMediaPlayer.prepareAsync(); mCurrentState = STATE_PREPARING; attachMediaController(); } catch (IOException ex) { Log.e("Unable to open content: " + mUri, ex); mCurrentState = STATE_ERROR; mTargetState = STATE_ERROR; mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0); return; } catch (IllegalArgumentException ex) { Log.e("Unable to open content: " + mUri, ex); mCurrentState = STATE_ERROR; mTargetState = STATE_ERROR; mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0); return; } }