|
|
@@ -1,34 +1,37 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
-import android.content.Context;
|
|
|
-import android.media.AudioManager;
|
|
|
-import android.media.MediaPlayer;
|
|
|
-import android.net.Uri;
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.view.GestureDetector;
|
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
-import android.view.WindowManager;
|
|
|
-import android.widget.MediaController;
|
|
|
-import android.widget.VideoView;
|
|
|
+import android.widget.ImageView;
|
|
|
|
|
|
import com.kfzs.duanduan.utils.StatusBarUtils;
|
|
|
+import com.sheep.gamegroup.absBase.AbsObserver;
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
-import com.sheep.gamegroup.util.DataUtil;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.gamegroup.view.customview.SheepGSYVideoPlayer;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
-import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.shuyu.gsyvideoplayer.GSYVideoManager;
|
|
|
+import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
|
|
|
+import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
|
|
|
+import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
|
|
|
+
|
|
|
+import java.util.Locale;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
+import io.reactivex.disposables.Disposable;
|
|
|
|
|
|
/**
|
|
|
- * Created by realicing on 2018/11/9.
|
|
|
+ * Created by realicing on 2019/3/6.
|
|
|
* realicing@sina.com
|
|
|
- * 视频播放
|
|
|
+ * 小绵羊3.5.1修改 -- 播放视频
|
|
|
*/
|
|
|
-public class ActPlayVideo extends BaseActivity implements MediaPlayer.OnInfoListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener, View.OnLayoutChangeListener {
|
|
|
+public class ActPlayVideo extends BaseActivity {
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
@@ -36,8 +39,11 @@ public class ActPlayVideo extends BaseActivity implements MediaPlayer.OnInfoList
|
|
|
super.onCreate(savedInstanceState);
|
|
|
}
|
|
|
|
|
|
- @BindView(R.id.videoView)
|
|
|
- VideoView videoView;
|
|
|
+ //播放
|
|
|
+ @BindView(R.id.detail_player)
|
|
|
+ StandardGSYVideoPlayer videoPlayer;
|
|
|
+ @BindView(R.id.gsy_video_play_iv)
|
|
|
+ View gsy_video_play_iv;//播放按钮
|
|
|
@BindView(R.id.video_loading)
|
|
|
View video_loading;
|
|
|
|
|
|
@@ -46,106 +52,202 @@ public class ActPlayVideo extends BaseActivity implements MediaPlayer.OnInfoList
|
|
|
return R.layout.act_play_video;
|
|
|
}
|
|
|
|
|
|
+ private String video_url;
|
|
|
+ private String video_cover_url;
|
|
|
+ private String video_title;
|
|
|
+ public static final String KEY_URL = "url";
|
|
|
+ public static final String KEY_TITLE = "title";
|
|
|
+ public static final String KEY_COVER = "cover";
|
|
|
+ //通过7牛云上的视频地址得到第一帧封面
|
|
|
+ public static String getCoverByUrl(String url){
|
|
|
+ return String.format(Locale.CHINA, "%s?vframe/%s/offset/%d", url, "jpg", 0);
|
|
|
+ }
|
|
|
+ public static String getCoverByUrl(String url, int index){
|
|
|
+ return String.format(Locale.CHINA, "%s?vframe/%s/offset/%d", url, "jpg", index);
|
|
|
+ }
|
|
|
+ public static String getCoverByUrl(String url, String scheme){
|
|
|
+ return String.format(Locale.CHINA, "%s?vframe/%s/offset/%d", url, scheme, 0);
|
|
|
+ }
|
|
|
+ public static String getCoverByUrl(String url, String scheme, int index){
|
|
|
+ return String.format(Locale.CHINA, "%s?vframe/%s/offset/%d", url, scheme, index);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
- initVolume();
|
|
|
- String url = DataUtil.getObject(getIntent(), String.class);
|
|
|
- Uri uri = Uri.parse(url);
|
|
|
- videoView.setOnInfoListener(this);
|
|
|
- videoView.setOnPreparedListener(this);
|
|
|
- videoView.setOnErrorListener(this);
|
|
|
- videoView.setOnCompletionListener(this);
|
|
|
- videoView.addOnLayoutChangeListener(this);
|
|
|
- videoView.setMediaController(new MediaController(this));
|
|
|
- videoView.setVideoURI(uri);
|
|
|
+ Intent intent = getIntent();
|
|
|
+ video_url = intent.getStringExtra(KEY_URL);
|
|
|
+ video_title = intent.getStringExtra(KEY_TITLE);
|
|
|
+ video_cover_url = intent.getStringExtra(KEY_COVER);
|
|
|
+ initPlay();
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isPlay = false;
|
|
|
+ private ImageView coverImageView;
|
|
|
+ private boolean isInit = false;
|
|
|
+
|
|
|
+ private void initPlay() {
|
|
|
+ if (!isInit) {
|
|
|
+ GSYVideoOptionBuilder gsyVideoOption = new GSYVideoOptionBuilder();
|
|
|
+ //增加封面
|
|
|
+ coverImageView = new ImageView(this);
|
|
|
+ coverImageView.setScaleType(ImageView.ScaleType.FIT_XY);
|
|
|
+ gsyVideoOption.setThumbImageView(coverImageView)
|
|
|
+ .setIsTouchWiget(false)
|
|
|
+ .setRotateViewAuto(true)
|
|
|
+ .setLockLand(true)
|
|
|
+ .setAutoFullWithSize(true)
|
|
|
+ .setShowFullAnimation(false)
|
|
|
+ .setNeedLockFull(true)
|
|
|
+ .setUrl(getVideoUrl())
|
|
|
+ .setCacheWithPlay(true)
|
|
|
+ .setVideoTitle(getVideoTitle())
|
|
|
+ .setVideoAllCallBack(new GSYSampleCallBack() {
|
|
|
+ @Override
|
|
|
+ public void onPrepared(String url, Object... objects) {
|
|
|
+ super.onPrepared(url, objects);
|
|
|
+ ViewUtil.setVisibility(video_loading, false);
|
|
|
+ isPlay = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAutoComplete(String url, Object... objects) {
|
|
|
+ super.onAutoComplete(url, objects);
|
|
|
+ videoPlayer.startPlayLogic();
|
|
|
+ }
|
|
|
+ }).build(videoPlayer);
|
|
|
+ isInit = true;
|
|
|
+ } else {
|
|
|
+ videoPlayer.setUp(getVideoUrl(), true, getVideoTitle());
|
|
|
+ }
|
|
|
+ videoPlayer.startPlayLogic();
|
|
|
+ ViewUtil.setVisibility(videoPlayer.getThumbImageViewLayout(), true);
|
|
|
+ ViewUtil.setImage(coverImageView, getVideoCoverUrl());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Disposable disposable;
|
|
|
+
|
|
|
+ private void playOrPause() {
|
|
|
+// gsy_video_play_iv
|
|
|
+ if (isPlaying()) {
|
|
|
+ isPlay = false;
|
|
|
+ ViewUtil.setVisibility(gsy_video_play_iv, true);
|
|
|
+ if (disposable != null && !disposable.isDisposed()) {
|
|
|
+ disposable.dispose();
|
|
|
+ }
|
|
|
+ ViewUtil.delay(new AbsObserver<Integer>() {
|
|
|
+ @Override
|
|
|
+ public void onSubscribe(Disposable d) {
|
|
|
+ disposable = d;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(Integer integer) {
|
|
|
+ ViewUtil.setVisibility(gsy_video_play_iv, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onComplete() {
|
|
|
+ disposable = null;
|
|
|
+ }
|
|
|
+ }, 2);
|
|
|
+ videoPlayer.onVideoPause();
|
|
|
+ } else {
|
|
|
+ isPlay = true;
|
|
|
+ ViewUtil.setVisibility(gsy_video_play_iv, false);
|
|
|
+ videoPlayer.onVideoResume();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //点击返回
|
|
|
+ public void onClickBackImg(View view) {
|
|
|
+ onBackPressed();
|
|
|
}
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
@Override
|
|
|
public void initListener() {
|
|
|
+ initPlay();
|
|
|
mGestureDetector = new GestureDetector(getApplicationContext(), mGestureListener);
|
|
|
- View.OnTouchListener listener = new View.OnTouchListener() {
|
|
|
- @Override
|
|
|
- public boolean onTouch(View v, MotionEvent event) {
|
|
|
- return onTouchEvent(event);
|
|
|
- }
|
|
|
- };
|
|
|
- videoView.setOnTouchListener(listener);
|
|
|
+ if (videoPlayer instanceof SheepGSYVideoPlayer)
|
|
|
+ ((SheepGSYVideoPlayer) videoPlayer).setGestureDetector(mGestureDetector);
|
|
|
}
|
|
|
- private GestureDetector mGestureDetector;
|
|
|
|
|
|
- //播放或者暂停
|
|
|
- private void playOrPause() {
|
|
|
- if(videoView.isPlaying()){
|
|
|
- pause();
|
|
|
- } else {
|
|
|
- play();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
}
|
|
|
- //播放
|
|
|
- private void play(){
|
|
|
- if(videoView == null){
|
|
|
- return;
|
|
|
- }
|
|
|
- videoView.start();
|
|
|
+
|
|
|
+ private GestureDetector mGestureDetector;
|
|
|
+
|
|
|
+ //是否正在播放视频
|
|
|
+ private boolean isPlaying() {
|
|
|
+ return isPlay;
|
|
|
}
|
|
|
- //暂停
|
|
|
- private void pause(){
|
|
|
- if(videoView == null){
|
|
|
- return;
|
|
|
- }
|
|
|
- videoView.pause();
|
|
|
+
|
|
|
+
|
|
|
+ //切换播放地址
|
|
|
+ protected void changeUrl() {
|
|
|
+ isPlay = false;
|
|
|
+ video_url = null;
|
|
|
+ video_cover_url = null;
|
|
|
+// videoPlayer.setUp(getVideoUrl(), true, getVideoTitle());
|
|
|
}
|
|
|
- //销毁
|
|
|
- private void destroy(){
|
|
|
- if(videoView == null){
|
|
|
- return;
|
|
|
- }
|
|
|
- videoView.stopPlayback();
|
|
|
+
|
|
|
+ private String getVideoUrl() {
|
|
|
+// return SheepApp.getHttpProxyCacheServer().getProxyUrl(video_url);
|
|
|
+ return video_url;
|
|
|
}
|
|
|
|
|
|
+ private String getVideoCoverUrl() {
|
|
|
+ return video_cover_url;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public boolean onTouchEvent(MotionEvent event) {
|
|
|
- return mGestureDetector.onTouchEvent(event);
|
|
|
+ private String getVideoTitle() {
|
|
|
+ return video_title;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onResume() {
|
|
|
+ videoPlayer.onVideoResume();
|
|
|
super.onResume();
|
|
|
- if(!isPauseByUser)
|
|
|
- play();
|
|
|
+ isPlay = true;
|
|
|
}
|
|
|
- //是否是用户手机暂停
|
|
|
- private boolean isPauseByUser;
|
|
|
+
|
|
|
@Override
|
|
|
protected void onPause() {
|
|
|
+ videoPlayer.onVideoPause();
|
|
|
+ //取消 播放按钮图片消失的事件
|
|
|
+ if (disposable != null && !disposable.isDisposed()) {
|
|
|
+ disposable.dispose();
|
|
|
+ }
|
|
|
super.onPause();
|
|
|
- if(videoView != null && videoView.isPlaying())
|
|
|
- isPauseByUser = false;
|
|
|
- if(video_loading != null)
|
|
|
- video_loading.setVisibility(View.VISIBLE);
|
|
|
- pause();
|
|
|
+ isPlay = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBackPressed() {
|
|
|
+ //释放所有
|
|
|
+ videoPlayer.setVideoAllCallBack(null);
|
|
|
+ super.onBackPressed();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
- destroy();
|
|
|
+ GSYVideoManager.releaseAllVideos();
|
|
|
super.onDestroy();
|
|
|
- mAudioManager = null;
|
|
|
}
|
|
|
|
|
|
-// //滑动方向
|
|
|
-// private int direction = 0;
|
|
|
-// //左右滑动
|
|
|
-// public static final int DIRECTION_LEFT_RIGHT = 1;
|
|
|
-// //上下滑动
|
|
|
-// public static final int DIRECTION_TOP_BOTTOM = 2;
|
|
|
+ // //滑动方向
|
|
|
+ private int direction = 0;
|
|
|
+ // //左右滑动
|
|
|
+ public static final int DIRECTION_LEFT_RIGHT = 1;
|
|
|
+ // //上下滑动
|
|
|
+ public static final int DIRECTION_TOP_BOTTOM = 2;
|
|
|
private GestureDetector.SimpleOnGestureListener mGestureListener = new GestureDetector.SimpleOnGestureListener() {
|
|
|
@Override
|
|
|
public boolean onDown(MotionEvent e) {
|
|
|
LogUtil.println("mGestureListener", "onDown");
|
|
|
-// direction = 0;
|
|
|
+ direction = 0;
|
|
|
return super.onDown(e);
|
|
|
}
|
|
|
|
|
|
@@ -158,187 +260,65 @@ public class ActPlayVideo extends BaseActivity implements MediaPlayer.OnInfoList
|
|
|
@Override
|
|
|
public boolean onSingleTapConfirmed(MotionEvent e) {
|
|
|
LogUtil.println("mGestureListener", "onSingleTapConfirmed");
|
|
|
-// if(isPlaying)
|
|
|
-// isPauseByUser = true;
|
|
|
-// playOrPause();
|
|
|
+ playOrPause();
|
|
|
return super.onSingleTapConfirmed(e);
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
- public boolean onScroll(MotionEvent e1, MotionEvent e2,
|
|
|
- float distanceX, float distanceY) {
|
|
|
- float mOldX = e1.getX(), mOldY = e1.getY();
|
|
|
- int y = (int) e2.getRawY();
|
|
|
- int windowWidth = ActPlayVideo.this.windowWidth;
|
|
|
- int windowHeight = ActPlayVideo.this.windowHeight;
|
|
|
- int lineMiddle = windowWidth / 2;
|
|
|
- if (mOldX > lineMiddle)// 左边滑动
|
|
|
- onBrightnessSlide((mOldY - y) / windowHeight);
|
|
|
- else if (mOldX < lineMiddle)// 右边滑动
|
|
|
- onVolumeSlide((mOldY - y) / windowHeight);
|
|
|
- return super.onScroll(e1, e2, distanceX, distanceY);
|
|
|
+ public boolean onDoubleTap(MotionEvent e) {
|
|
|
+ LogUtil.println("mGestureListener", "onDoubleTap");
|
|
|
+ return super.onDoubleTap(e);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-// @Override
|
|
|
-// public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) {
|
|
|
-// LogUtil.println("mGestureListener", distanceX, distanceY);
|
|
|
-// if (event1 == null || event2 == null) {
|
|
|
-// return super.onScroll(event1, event2, distanceX, distanceY);
|
|
|
-// }
|
|
|
-// if (direction == 0) {
|
|
|
-// float a = Math.abs(distanceY);
|
|
|
-// float b = Math.abs(distanceX);
|
|
|
-// if (a > b) {
|
|
|
-// LogUtil.println("mGestureListener", "上下滑动");
|
|
|
-// direction = DIRECTION_TOP_BOTTOM;
|
|
|
-// } else if (b > a) {
|
|
|
-// LogUtil.println("mGestureListener", "左右滑动");
|
|
|
-// direction = DIRECTION_LEFT_RIGHT;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return super.onScroll(event1, event2, distanceX, distanceY);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
|
|
|
-// LogUtil.println("mGestureListener", velocityX, velocityY);
|
|
|
-// if (event1 == null || event2 == null) {
|
|
|
-// return super.onFling(event1, event2, velocityX, velocityY);
|
|
|
-// }
|
|
|
-// final int FLING_MIN_DISTANCE = 100, FLING_MIN_VELOCITY = 200;
|
|
|
-// if (event1.getX() - event2.getX() > FLING_MIN_DISTANCE
|
|
|
-// && Math.abs(velocityX) > FLING_MIN_VELOCITY) {
|
|
|
-// // Fling left
|
|
|
-// LogUtil.println("mGestureListener", "Fling left");
|
|
|
-// //音量增益减
|
|
|
-// } else if (event2.getX() - event1.getX() > FLING_MIN_DISTANCE
|
|
|
-// && Math.abs(velocityX) > FLING_MIN_VELOCITY) {
|
|
|
-// // Fling right
|
|
|
-// LogUtil.println("mGestureListener", "Fling rigth");
|
|
|
-// //音量增益加
|
|
|
-// } else if (event2.getY() - event1.getY() > FLING_MIN_DISTANCE
|
|
|
-// && Math.abs(velocityY) > FLING_MIN_VELOCITY) {
|
|
|
-// if (direction == DIRECTION_LEFT_RIGHT) {
|
|
|
-// // Fling down
|
|
|
-// LogUtil.println("mGestureListener", "Fling down");
|
|
|
-// //频道减
|
|
|
-// }
|
|
|
-// } else if (event1.getY() - event2.getY() > FLING_MIN_DISTANCE
|
|
|
-// && Math.abs(velocityY) > FLING_MIN_VELOCITY) {
|
|
|
-// if (direction == DIRECTION_LEFT_RIGHT) {
|
|
|
-// // Fling up
|
|
|
-// LogUtil.println("mGestureListener", "Fling up");
|
|
|
-// //频道加
|
|
|
-// }
|
|
|
-// }
|
|
|
-//// return super.onFling(event1, event2, velocityX, velocityY);
|
|
|
-// return false;
|
|
|
-// }
|
|
|
- };
|
|
|
- private AudioManager mAudioManager;
|
|
|
- private int mMaxVolume;//最大音量
|
|
|
- private int mVolume;//当前音量
|
|
|
- private void initVolume(){
|
|
|
- mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
|
- if(mAudioManager != null)
|
|
|
- mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
|
|
- }
|
|
|
- //滑动改变音量
|
|
|
- private void onVolumeSlide(float percent) {
|
|
|
- if (mVolume == -1) {
|
|
|
- mVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
|
|
- if (mVolume < 0)
|
|
|
- mVolume = 0;
|
|
|
-
|
|
|
- // 显示
|
|
|
-// mOperationBg.setImageResource(R.drawable.video_volumn_bg);
|
|
|
-// mVolumeBrightnessLayout.setVisibility(View.VISIBLE);
|
|
|
+ @Override
|
|
|
+ public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) {
|
|
|
+ LogUtil.println("mGestureListener", distanceX, distanceY);
|
|
|
+ if (event1 == null || event2 == null) {
|
|
|
+ return super.onScroll(event1, event2, distanceX, distanceY);
|
|
|
+ }
|
|
|
+ if (direction == 0) {
|
|
|
+ float a = Math.abs(distanceY);
|
|
|
+ float b = Math.abs(distanceX);
|
|
|
+ if (a > b) {
|
|
|
+ LogUtil.println("mGestureListener", "上下滑动");
|
|
|
+ direction = DIRECTION_TOP_BOTTOM;
|
|
|
+ } else if (b > a) {
|
|
|
+ LogUtil.println("mGestureListener", "左右滑动");
|
|
|
+ direction = DIRECTION_LEFT_RIGHT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return super.onScroll(event1, event2, distanceX, distanceY);
|
|
|
}
|
|
|
|
|
|
- int index = (int) (percent * mMaxVolume) + mVolume;
|
|
|
- if (index > mMaxVolume)
|
|
|
- index = mMaxVolume;
|
|
|
- else if (index < 0)
|
|
|
- index = 0;
|
|
|
-
|
|
|
- // 变更声音
|
|
|
- mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, index, 0);
|
|
|
- // 变更进度条
|
|
|
-// ViewGroup.LayoutParams lp = mOperationPercent.getLayoutParams();
|
|
|
-// lp.width = findViewById(R.id.operation_full).getLayoutParams().width * index / mMaxVolume;
|
|
|
-// mOperationPercent.setLayoutParams(lp);
|
|
|
- }
|
|
|
- private float mBrightness = -1;
|
|
|
- //滑动改变亮度
|
|
|
- private void onBrightnessSlide(float percent) {
|
|
|
- if (mBrightness < 0) {
|
|
|
- mBrightness = getWindow().getAttributes().screenBrightness;
|
|
|
- if (mBrightness <= 0.00f)
|
|
|
- mBrightness = 0.50f;
|
|
|
- if (mBrightness < 0.01f)
|
|
|
- mBrightness = 0.01f;
|
|
|
-
|
|
|
- // 显示
|
|
|
-// mOperationBg.setImageResource(R.drawable.video_brightness_bg);
|
|
|
-// mVolumeBrightnessLayout.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
- WindowManager.LayoutParams lpa = getWindow().getAttributes();
|
|
|
- lpa.screenBrightness = mBrightness + percent;
|
|
|
- if (lpa.screenBrightness > 1.0f)
|
|
|
- lpa.screenBrightness = 1.0f;
|
|
|
- else if (lpa.screenBrightness < 0.01f)
|
|
|
- lpa.screenBrightness = 0.01f;
|
|
|
- getWindow().setAttributes(lpa);
|
|
|
-
|
|
|
-// ViewGroup.LayoutParams lp = mOperationPercent.getLayoutParams();
|
|
|
-// lp.width = (int) (findViewById(R.id.operation_full).getLayoutParams().width * lpa.screenBrightness);
|
|
|
-// mOperationPercent.setLayoutParams(lp);
|
|
|
- }
|
|
|
- @Override
|
|
|
- public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
|
|
|
- LogUtil.println("ActPlayVideo", "onInfo what = " + what + " extra = " + extra);
|
|
|
- if (!mediaPlayer.isLooping())
|
|
|
- mediaPlayer.setLooping(true);
|
|
|
- switch (what) {
|
|
|
- case MediaPlayer.MEDIA_INFO_BUFFERING_START:
|
|
|
- LogUtil.println("ActPlayVideo", "onInfo", "正在缓冲");
|
|
|
- if(video_loading != null)
|
|
|
- video_loading.setVisibility(View.VISIBLE);
|
|
|
- break;
|
|
|
- case MediaPlayer.MEDIA_INFO_BUFFERING_END:
|
|
|
- case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
|
|
|
- LogUtil.println("ActPlayVideo", "onInfo", "缓冲完成");
|
|
|
- //缓存完成,继续播放
|
|
|
- if(video_loading != null)
|
|
|
- video_loading.setVisibility(View.GONE);
|
|
|
- break;
|
|
|
+ @Override
|
|
|
+ public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
|
|
|
+ LogUtil.println("mGestureListener", velocityX, velocityY);
|
|
|
+ if (event1 == null || event2 == null) {
|
|
|
+ return super.onFling(event1, event2, velocityX, velocityY);
|
|
|
+ }
|
|
|
+ final int FLING_MIN_DISTANCE = 100, FLING_MIN_VELOCITY = 200;
|
|
|
+ if (event1.getX() - event2.getX() > FLING_MIN_DISTANCE
|
|
|
+ && Math.abs(velocityX) > FLING_MIN_VELOCITY) {
|
|
|
+ // Fling left
|
|
|
+ } else if (event2.getX() - event1.getX() > FLING_MIN_DISTANCE
|
|
|
+ && Math.abs(velocityX) > FLING_MIN_VELOCITY) {
|
|
|
+ // Fling right
|
|
|
+ } else if (event2.getY() - event1.getY() > FLING_MIN_DISTANCE
|
|
|
+ && Math.abs(velocityY) > FLING_MIN_VELOCITY) {
|
|
|
+ if (direction == DIRECTION_TOP_BOTTOM) {
|
|
|
+ // Fling down
|
|
|
+ LogUtil.println("mGestureListener", "Fling down");
|
|
|
+ }
|
|
|
+ } else if (event1.getY() - event2.getY() > FLING_MIN_DISTANCE
|
|
|
+ && Math.abs(velocityY) > FLING_MIN_VELOCITY) {
|
|
|
+ if (direction == DIRECTION_TOP_BOTTOM) {
|
|
|
+ // Fling up
|
|
|
+ LogUtil.println("mGestureListener", "Fling up");
|
|
|
+ }
|
|
|
+ }
|
|
|
+// return super.onFling(event1, event2, velocityX, velocityY);
|
|
|
+ return false;
|
|
|
}
|
|
|
- return false;
|
|
|
- }
|
|
|
- @Override
|
|
|
- public void onPrepared(MediaPlayer mediaPlayer) {
|
|
|
- LogUtil.println("ActPlayVideo", "onPrepared");
|
|
|
- if(video_loading != null)
|
|
|
- video_loading.setVisibility(View.GONE);
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
|
|
|
- LogUtil.println("ActPlayVideo", "onInfo what = " + what + " extra = " + extra);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCompletion(MediaPlayer mediaPlayer) {
|
|
|
- LogUtil.println("ActPlayVideo", "onCompletion");
|
|
|
- }
|
|
|
-
|
|
|
- private int windowWidth = G.WIDTH;
|
|
|
- private int windowHeight = G.HEIGHT;
|
|
|
- @Override
|
|
|
- public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
|
|
- LogUtil.println("ActPlayVideo", "onLayoutChange", left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom);
|
|
|
- this.windowWidth = left + right;
|
|
|
- this.windowHeight = top + bottom;
|
|
|
- }
|
|
|
+ };
|
|
|
}
|