Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #34 from prophet173/master
Browse files Browse the repository at this point in the history
Added DoubleTap2Seek
  • Loading branch information
halilozercan authored Aug 15, 2017
2 parents f46e3f1 + 3940e1a commit 605be55
Show file tree
Hide file tree
Showing 25 changed files with 115 additions and 13 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Better Video Player is a rethought version(fork) of [Easy Video Player](https://
* __Very configurable__ There are lots of options available to make the player behave exactly how you want it to behave.
* __Adaptive__ The player use the colors of your (AppCompat) Activity theme automatically.
* __Swipe Gestures__ Supports the common on-screen scroll behavior which is used by MXPlayer, VLC and other Android media players.
* __Double tap to seek__ Very youtube like double tap to seek with custom time.

---

Expand Down Expand Up @@ -301,6 +302,9 @@ player.hideControls().
// Shows the controls if they're hidden, hides them if they're shown.
player.toggleControls();

// Enables double tap to seek like in Youtube. Input: seek time in MS
player.enableDoubleTapSeek(int);

// Returns true if the default controls are currently shown.
player.isControlsShown();

Expand Down Expand Up @@ -402,4 +406,4 @@ The programmatic configuration options shown above can also be configured direct

#### Final note
While I try to complete this README, you can check out Sample project of this repo. It will be updated often and
written code sometimes help a lot more than a poorly written documentation.
written code sometimes help a lot more than a poorly written documentation.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
Expand Down Expand Up @@ -68,6 +70,7 @@
* @author Aidan Follestad
* Modified and improved by Halil Ozercan
*/
@SuppressWarnings("ALL")
public class BetterVideoPlayer extends RelativeLayout implements IUserMethods,
TextureView.SurfaceTextureListener, MediaPlayer.OnPreparedListener,
MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnCompletionListener,
Expand All @@ -78,14 +81,15 @@ public class BetterVideoPlayer extends RelativeLayout implements IUserMethods,
private static final int UPDATE_INTERVAL = 100;

private SpinKitView mProgressBar;
private TextView mPositionTextView;
private TextView mPositionTextView, viewForward, viewBackward;

private CaptionsView mSubView;
private AudioManager am;
private Toolbar mToolbar;
private String mTitle;
private int mSubViewTextSize;
private int mSubViewTextColor;
private Context context;

/**
* Window that hold the player. Necessary for setting brightness.
Expand Down Expand Up @@ -157,6 +161,8 @@ public BetterVideoPlayer(Context context, AttributeSet attrs, int defStyleAttr)
private int mInitialTextureHeight;
private Handler mHandler;

private int viewVisibility;

private Uri mSource;
private Map<String, String> headers;

Expand All @@ -182,7 +188,7 @@ public BetterVideoPlayer(Context context, AttributeSet attrs, int defStyleAttr)

private void init(Context context, AttributeSet attrs) {
setBackgroundColor(Color.BLACK);

this.context = context;
if (attrs != null) {
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
Expand Down Expand Up @@ -289,16 +295,21 @@ public void setButtonDrawable(@BetterVideoPlayer.LoadingStyle int type,
switch (type){
case PLAY_BUTTON:
mPlayDrawable = drawable;
if (!isPlaying()) mBtnPlayPause.setImageDrawable(drawable);
if (!isPlaying()) {
mBtnPlayPause.setImageDrawable(drawable);
}
break;
case PAUSE_BUTTON:
mPauseDrawable = drawable;
if (isPlaying()) mBtnPlayPause.setImageDrawable(drawable);
if (isPlaying()) {
mBtnPlayPause.setImageDrawable(drawable);
}
break;
case RESTART_BUTTON:
mPauseDrawable = drawable;
if (mPlayer != null && mPlayer.getCurrentPosition() >= mPlayer.getDuration())
if (mPlayer != null && mPlayer.getCurrentPosition() >= mPlayer.getDuration()) {
mBtnPlayPause.setImageDrawable(drawable);
}
break;
}
}
Expand Down Expand Up @@ -365,6 +376,66 @@ private void prepare() {
}
}

public void setDoubleTap(final int seek) {
mClickFrame.setOnTouchListener(new View.OnTouchListener() {

int screenWidthHalf = Util.getScreenWidth(context)/2;

private GestureDetector gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
int seekSec = seek/1000;
viewForward.setText(seekSec + " seconds");
viewBackward.setText(seekSec + " seconds");
if(e.getX() > screenWidthHalf) {
animateViewFade(viewForward, 1);
seekTo(getCurrentPosition() + seek);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
animateViewFade(viewForward, 0);
}
}, 500);
} else {
animateViewFade(viewBackward, 1);
seekTo(getCurrentPosition() - seek);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
animateViewFade(viewBackward, 0);
}
}, 500);
}
return true;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
toggleControls();
return true;
}
});

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
gestureDetector.onTouchEvent(motionEvent);
return true;
}
});
}

private void animateViewFade(final View view, final int alpha) {
viewVisibility = alpha > 0 ? View.VISIBLE : View.INVISIBLE;
view.animate()
.alpha(alpha)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
view.setVisibility(viewVisibility);
}
});
}

private void setControlsEnabled(boolean enabled) {
if (mSeeker == null)
return;
Expand Down Expand Up @@ -829,6 +900,9 @@ protected void onFinishInflate() {
mTextureView = (TextureView) mTextureFrame.findViewById(R.id.textureview);
mTextureView.setSurfaceTextureListener(this);

viewForward = (TextView) mTextureFrame.findViewById(R.id.view_forward);
viewBackward = (TextView) mTextureFrame.findViewById(R.id.view_backward);

// Inflate and add progress
mProgressFrame = li.inflate(R.layout.bvp_include_progress, this, false);
mProgressBar = (SpinKitView) mProgressFrame.findViewById(R.id.spin_kit);
Expand Down Expand Up @@ -919,15 +993,13 @@ public void onClick(View view) {
if (view.getId() == R.id.btnPlayPause) {
if (mPlayer.isPlaying()) {
pause();
}
else {
} else {
if (mHideControlsOnPlay && !mControlsDisabled) {
mHandler.postDelayed(hideControlsRunnable, 500);
}
start();
}
}
else if(view.getId() == R.id.duration){
} else if(view.getId() == R.id.duration){
mShowTotalDuration = !mShowTotalDuration;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*/
public class Util {

public static int getScreenWidth(Context context) {
return context.getResources().getDisplayMetrics().widthPixels;
}

public static String getDurationString(long durationMs, boolean negativePrefix) {
long hours = TimeUnit.MILLISECONDS.toHours(durationMs);
long minutes = TimeUnit.MILLISECONDS.toMinutes(durationMs);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif"
android:textColor="#fff"
android:textSize="@dimen/bvp_text_size_medium"
Expand All @@ -51,7 +50,7 @@
android:gravity="center"
android:layout_alignTop="@+id/btnPlayPause"
android:layout_alignBottom="@+id/btnPlayPause"
android:layout_marginRight="@dimen/bvp_content_inset_half" />
android:layout_marginEnd="@dimen/bvp_content_inset_half" />

<ImageButton
android:id="@+id/btnPlayPause"
Expand All @@ -61,7 +60,6 @@
android:src="@drawable/bvp_action_play"
tools:ignore="ContentDescription"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

</RelativeLayout>
24 changes: 24 additions & 0 deletions bettervideoplayer/src/main/res/layout/bvp_include_surface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,29 @@
android:id="@+id/textureview"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<TextView
android:id="@+id/view_forward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:visibility="gone"
android:alpha="0"
android:drawableTop="@drawable/ic_forward"
android:layout_margin="10dp"
android:gravity="center"
android:textColor="@android:color/white"/>

<TextView
android:id="@+id/view_backward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:visibility="gone"
android:alpha="0"
android:drawableTop="@drawable/ic_backward"
android:layout_margin="10dp"
android:gravity="center"
android:textColor="@android:color/white"/>

</FrameLayout>

0 comments on commit 605be55

Please sign in to comment.