public void setNativeMode(boolean value) { nativeMode = value; if (nativeMode) { mVideoView.setVisibility(View.VISIBLE); } else { mVideoView.setVisibility(View.GONE); } }
public void pause() { if (nativeMode) { mVideoView.pause(); mVideoView.setKeepScreenOn(false); } else { mVlcPlayer.pause(); mSurfaceView.setKeepScreenOn(false); } }
public void play() { if (nativeMode) { mVideoView.start(); mVideoView.setKeepScreenOn(true); } else { mVlcPlayer.play(); mSurfaceView.setKeepScreenOn(true); // work around losing audio when pausing bug int sav = mVlcPlayer.getAudioTrack(); mVlcPlayer.setAudioTrack(-1); mVlcPlayer.setAudioTrack(sav); // } }
public void setVideoFullSize() { if (normalHeight == 0) return; FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) (nativeMode ? mVideoView.getLayoutParams() : mSurfaceView.getLayoutParams()); lp.height = normalHeight; lp.width = normalWidth; if (nativeMode) { lp.rightMargin = 0; lp.bottomMargin = 0; mVideoView.setLayoutParams(lp); mVideoView.invalidate(); } else mSurfaceView.setLayoutParams(lp); isContracted = false; }
public void showSurface() { if (nativeMode) { mVideoView.setVisibility(View.VISIBLE); } else { mSurfaceView.setVisibility(View.VISIBLE); } }
public void stopPlayback() { if (nativeMode) { mVideoView.stopPlayback(); } else { mVlcPlayer.stop(); } }
public void start() { if (nativeMode) { mVideoView.start(); mVideoView.setKeepScreenOn(true); normalWidth = mVideoView.getLayoutParams().width; normalHeight = mVideoView.getLayoutParams().height; } else { if (!mSurfaceReady) { TvApp.getApplication().getLogger().Error("Attempt to play before surface ready"); return; } if (!mVlcPlayer.isPlaying()) { mVlcPlayer.play(); } } }
public void setOnCompletionListener(final PlaybackListener listener) { mVideoView.setOnCompletionListener( new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { listener.onEvent(); stopProgressLoop(); } }); mVlcHandler.setOnCompletionListener(listener); }
public void setOnPreparedListener(final PlaybackListener listener) { mVideoView.setOnPreparedListener( new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mNativeMediaPlayer = mp; listener.onEvent(); startProgressLoop(); } }); mVlcHandler.setOnPreparedListener(listener); }
public void setOnErrorListener(final PlaybackListener listener) { mVideoView.setOnErrorListener( new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { listener.onEvent(); stopProgressLoop(); return true; } }); mVlcHandler.setOnErrorListener(listener); }
public void contractVideo(int height) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) (nativeMode ? mVideoView.getLayoutParams() : mSurfaceView.getLayoutParams()); if (isContracted) return; Activity activity = TvApp.getApplication().getCurrentActivity(); int sw = activity.getWindow().getDecorView().getWidth(); int sh = activity.getWindow().getDecorView().getHeight(); float ar = (float) sw / sh; lp.height = height; lp.width = (int) Math.ceil(height * ar); lp.rightMargin = ((lp.width - normalWidth) / 2) - 110; lp.bottomMargin = ((lp.height - normalHeight) / 2) - 50; if (nativeMode) { mVideoView.setLayoutParams(lp); mVideoView.invalidate(); } else mSurfaceView.setLayoutParams(lp); isContracted = true; }
public long getCurrentPosition() { if (nativeMode) return mVideoView.getCurrentPosition(); long time = mVlcPlayer.getTime(); if (mForcedTime != -1 && mLastTime != -1) { /* XXX: After a seek, mLibVLC.getTime can return the position before or after * the seek position. Therefore we return mForcedTime in order to avoid the seekBar * to move between seek position and the actual position. * We have to wait for a valid position (that is after the seek position). * to re-init mLastTime and mForcedTime to -1 and return the actual position. */ if (mLastTime > mForcedTime) { if (time <= mLastTime && time > mForcedTime) mLastTime = mForcedTime = -1; } else { if (time > mForcedTime) mLastTime = mForcedTime = -1; } } return mForcedTime == -1 ? time : mForcedTime; }
public void setVideoPath(String path) { mCurrentVideoPath = path; if (nativeMode) { try { mVideoView.setVideoPath(path); } catch (IllegalStateException e) { TvApp.getApplication() .getLogger() .ErrorException("Unable to set video path. Probably backing out.", e); } } else { mSurfaceHolder.setKeepScreenOn(true); mCurrentMedia = new Media(mLibVLC, Uri.parse(path)); mCurrentMedia.parse(); mVlcPlayer.setMedia(mCurrentMedia); mCurrentMedia.release(); } }
public long seekTo(long pos) { if (nativeMode) { Long intPos = pos; mVideoView.seekTo(intPos.intValue()); return pos; } else { if (mVlcPlayer == null || !mVlcPlayer.isSeekable()) return -1; mForcedTime = pos; mLastTime = mVlcPlayer.getTime(); TvApp.getApplication().getLogger().Info("VLC length in seek is: " + mVlcPlayer.getLength()); try { if (getDuration() > 0) mVlcPlayer.setPosition((float) pos / getDuration()); else mVlcPlayer.setTime(pos); return pos; } catch (Exception e) { TvApp.getApplication().getLogger().ErrorException("Error seeking in VLC", e); Utils.showToast(mActivity, "Unable to seek"); return -1; } } }
public boolean isPlaying() { return nativeMode ? mVideoView.isPlaying() : mVlcPlayer != null && mVlcPlayer.isPlaying(); }
public long getDuration() { return nativeMode ? mVideoView.getDuration() : mVlcPlayer.getLength() > 0 ? mVlcPlayer.getLength() : mMetaDuration; }