Skip to content

Commit

Permalink
修复滑动取消后GestureView依旧显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Doikki committed Mar 10, 2020
1 parent f964f03 commit 67c49e5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public abstract class GestureVideoController extends BaseVideoController impleme
private boolean mIsGestureEnabled = true;
private int mStreamVolume;
private float mBrightness;
private int mPosition;
private boolean mNeedSeek;
private int mSeekPosition;
private boolean mFirstTouch;
private boolean mChangePosition;
private boolean mChangeBrightness;
Expand Down Expand Up @@ -228,8 +227,7 @@ protected void slideToChangePosition(float deltaX) {
((IGestureComponent) component).onPositionChange(position, currentPosition, duration);
}
}
mPosition = position;
mNeedSeek = true;
mSeekPosition = position;
}

protected void slideToChangeBrightness(float deltaY) {
Expand Down Expand Up @@ -274,22 +272,35 @@ protected void slideToChangeVolume(float deltaY) {

@Override
public boolean onTouchEvent(MotionEvent event) {
boolean detectedUp = event.getAction() == MotionEvent.ACTION_UP;
if (!mGestureDetector.onTouchEvent(event) && detectedUp) {
for (Map.Entry<IControlComponent, Boolean> next : mControlComponents.entrySet()) {
IControlComponent component = next.getKey();
if (component instanceof IGestureComponent) {
((IGestureComponent) component).onStopSlide();
}
}
if (mNeedSeek) {
mControlWrapper.seekTo(mPosition);
mNeedSeek = false;
//滑动结束时事件处理
if (!mGestureDetector.onTouchEvent(event)) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_UP:
stopSlide();
if (mSeekPosition > 0) {
mControlWrapper.seekTo(mSeekPosition);
mSeekPosition = 0;
}
break;
case MotionEvent.ACTION_CANCEL:
stopSlide();
mSeekPosition = 0;
break;
}
}
return super.onTouchEvent(event);
}

private void stopSlide() {
for (Map.Entry<IControlComponent, Boolean> next : mControlComponents.entrySet()) {
IControlComponent component = next.getKey();
if (component instanceof IGestureComponent) {
((IGestureComponent) component).onStopSlide();
}
}
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions dkplayer-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
<activity
android:name=".activity.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -50,7 +49,8 @@
<activity
android:name=".activity.api.PlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden"/>
<activity
android:name=".activity.extend.DanmakuActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
Expand Down Expand Up @@ -105,6 +106,7 @@ protected void initView() {

//在控制器上显示调试信息
controller.addControlComponent(new DebugInfoView(this));
//在LogCat显示调试信息
controller.addControlComponent(new PlayerMonitor());

//如果你不想要UI,不要设置控制器即可
Expand All @@ -127,6 +129,17 @@ protected void initView() {

mVideoView.start();
}

//播放其他视频
EditText etOtherVideo = findViewById(R.id.et_other_video);
findViewById(R.id.btn_start_play).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mVideoView.release();
mVideoView.setUrl(etOtherVideo.getText().toString());
mVideoView.start();
}
});
}

private VideoView.OnStateChangeListener mOnStateChangeListener = new VideoView.SimpleOnStateChangeListener() {
Expand Down
24 changes: 21 additions & 3 deletions dkplayer-sample/src/main/res/layout/activity_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/player"
app:layout_constraintBottom_toBottomOf="parent">
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/player">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
Expand Down Expand Up @@ -154,6 +154,24 @@
android:layout_width="300dp"
android:layout_height="wrap_content" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/et_other_video"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="其他地址" />

<Button
android:id="@+id/btn_start_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始播放" />
</LinearLayout>

</LinearLayout>

</ScrollView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

/**
* 直播/点播控制器
* 注意:此控制器仅做一个参考,如果想定制ui,你可以直接继承GestureVideoController或者BaseVideoController实现
* 你自己的控制器
* Created by dueeeke on 2017/4/7.
*/

Expand Down

0 comments on commit 67c49e5

Please sign in to comment.