|
|
@@ -2,8 +2,6 @@ package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.content.Intent;
|
|
|
-import android.media.MediaPlayer;
|
|
|
-import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.design.widget.CheckableImageButton;
|
|
|
@@ -14,9 +12,7 @@ import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
-import android.widget.VideoView;
|
|
|
|
|
|
-import com.danikula.videocache.CacheListener;
|
|
|
import com.kfzs.duanduan.utils.StatusBarUtils;
|
|
|
import com.sheep.gamegroup.absBase.BaseUMActivity;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
@@ -31,12 +27,16 @@ import com.sheep.gamegroup.util.LogUtil;
|
|
|
import com.sheep.gamegroup.util.TestUtil;
|
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
|
import com.sheep.gamegroup.util.share.ShareLinkConfig;
|
|
|
+import com.sheep.gamegroup.view.customview.SheepGSYVideoPlayer;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
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 com.umeng.socialize.bean.SHARE_MEDIA;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
@@ -48,7 +48,7 @@ import io.reactivex.schedulers.Schedulers;
|
|
|
* realicing@sina.com
|
|
|
* 小绵羊3.4.5新增 -- 视频详情
|
|
|
*/
|
|
|
-public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfoListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener, CacheListener {
|
|
|
+public class ActVideoDetail extends BaseUMActivity {
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
@@ -57,10 +57,8 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
}
|
|
|
|
|
|
//播放
|
|
|
- @BindView(R.id.videoView)
|
|
|
- VideoView videoView;
|
|
|
- @BindView(R.id.videoCoverIv)
|
|
|
- ImageView videoCoverIv;
|
|
|
+ @BindView(R.id.detail_player)
|
|
|
+ StandardGSYVideoPlayer videoPlayer;
|
|
|
@BindView(R.id.video_loading)
|
|
|
View video_loading;
|
|
|
|
|
|
@@ -92,7 +90,8 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
private int video_id;
|
|
|
private int user_id;
|
|
|
private String video_url;
|
|
|
- private int orientation = 0;
|
|
|
+ private String video_cover_url;
|
|
|
+ private String video_title;
|
|
|
private DiscoveryVideo newVideo;
|
|
|
private ArrayList<DiscoveryVideo> videoList;
|
|
|
private int position;
|
|
|
@@ -115,7 +114,8 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
video_id = lastVideo.getId();
|
|
|
user_id = lastVideo.getUser_id();
|
|
|
video_url = lastVideo.getResource();
|
|
|
- orientation = lastVideo.getOrientation();
|
|
|
+ video_title = lastVideo.getTitle();
|
|
|
+ video_cover_url = lastVideo.getCover();
|
|
|
loadVideoData(lastVideo);
|
|
|
}
|
|
|
|
|
|
@@ -127,8 +127,6 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
ViewUtil.setVisibility2(video_focus_iv, false);
|
|
|
return;
|
|
|
}
|
|
|
- ViewUtil.setVisibility(videoCoverIv, true);
|
|
|
- ViewUtil.setImage(videoCoverIv, discoveryVideo.getCover());
|
|
|
ViewUtil.setAvatar(video_avatar_iv, discoveryVideo.getAvatar());
|
|
|
ViewUtil.setText(video_like_tv, discoveryVideo.getLike());
|
|
|
ViewUtil.setText(video_title_tv, discoveryVideo.getTitle());
|
|
|
@@ -138,35 +136,47 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
ViewUtil.setChecked(video_focus_iv, discoveryVideo.isIs_focus_user());
|
|
|
}
|
|
|
|
|
|
+ private boolean isPlay = false;
|
|
|
+ private boolean isPause = false;
|
|
|
+ private ImageView coverImageView;
|
|
|
+ private boolean isInit = false;
|
|
|
private void initPlay() {
|
|
|
- videoView.setOnInfoListener(this);
|
|
|
- videoView.setOnPreparedListener(this);
|
|
|
- videoView.setOnErrorListener(this);
|
|
|
- videoView.setOnCompletionListener(this);
|
|
|
-// videoView.setMediaController(new MediaController(this));
|
|
|
- videoView.setVideoURI(getUri());
|
|
|
-// videoView.setVideoPath(getUrl());
|
|
|
-// videoView.start();
|
|
|
- resetVideoOrientation();
|
|
|
- }
|
|
|
- //重新设置视频的方向,videoView没法设置方向
|
|
|
- private void resetVideoOrientation(){
|
|
|
-// if(orientation > 0 && orientation < 360)
|
|
|
-// videoView.setRotation(orientation);
|
|
|
- }
|
|
|
- private boolean isResister = false;
|
|
|
- //转化地址
|
|
|
- private String getUrl(){
|
|
|
- if(isResister)
|
|
|
- SheepApp.getHttpProxyCacheServer().registerCacheListener(this, video_url);
|
|
|
- return SheepApp.getHttpProxyCacheServer().getProxyUrl(video_url);
|
|
|
- }
|
|
|
- //转化地址
|
|
|
- private Uri getUri(){
|
|
|
- String proxyUrl = getUrl();
|
|
|
- Uri uri = Uri.parse(proxyUrl);
|
|
|
- LogUtil.println(ActVideoDetail.class.getSimpleName(),"\n", video_url, "\n", proxyUrl);
|
|
|
- return uri;
|
|
|
+ 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());
|
|
|
}
|
|
|
|
|
|
//点赞
|
|
|
@@ -278,13 +288,8 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -304,10 +309,11 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
if (newVideo != null) {
|
|
|
user_id = newVideo.getUser_id();
|
|
|
if (TextUtils.isEmpty(video_url)) {
|
|
|
- video_url = newVideo.getResource();
|
|
|
+ initVideoData(newVideo);
|
|
|
initPlay();
|
|
|
+ } else {
|
|
|
+ loadVideoData(newVideo);
|
|
|
}
|
|
|
- loadVideoData(newVideo);
|
|
|
}
|
|
|
// ActionUtil.getInstance().addNextAction(FgtArticleVideo.class.getSimpleName(), IRefresh.class.getSimpleName());
|
|
|
hideProgress();
|
|
|
@@ -323,12 +329,6 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected void onResume() {
|
|
|
- super.onResume();
|
|
|
- updateVideoCommentNo();
|
|
|
- }
|
|
|
-
|
|
|
//更新评论数量
|
|
|
private void updateVideoCommentNo() {
|
|
|
SheepApp.getInstance().getNetComponent().getApiService().getGameUserAppCommentList(1,1, video_id, ApiJSONUtil.COMMENT_TYPE_VIDEO)
|
|
|
@@ -349,74 +349,55 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
|
|
|
private GestureDetector mGestureDetector;
|
|
|
|
|
|
- //播放或者暂停
|
|
|
- private void playOrPause() {
|
|
|
- if (isPlaying()) {
|
|
|
- pause();
|
|
|
- } else {
|
|
|
- play();
|
|
|
- }
|
|
|
- }
|
|
|
//是否正在播放视频
|
|
|
private boolean isPlaying(){
|
|
|
- return videoView != null && videoView.isPlaying();
|
|
|
+ return isPlay && !isPause;
|
|
|
}
|
|
|
|
|
|
- //播放
|
|
|
- private void play() {
|
|
|
- if (videoView == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- videoView.start();
|
|
|
- }
|
|
|
|
|
|
- //暂停
|
|
|
- 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();
|
|
|
- if(isResister)
|
|
|
- SheepApp.getHttpProxyCacheServer().unregisterCacheListener(this, video_url);
|
|
|
+ private String getVideoUrl(){
|
|
|
+// return SheepApp.getHttpProxyCacheServer().getProxyUrl(video_url);
|
|
|
+ return video_url;
|
|
|
+ }
|
|
|
+ private String getVideoCoverUrl(){
|
|
|
+ return video_cover_url;
|
|
|
+ }
|
|
|
+ private String getVideoTitle(){
|
|
|
+ return video_title;
|
|
|
}
|
|
|
-
|
|
|
|
|
|
@Override
|
|
|
- public boolean onTouchEvent(MotionEvent event) {
|
|
|
- return mGestureDetector.onTouchEvent(event);
|
|
|
+ protected void onResume() {
|
|
|
+ videoPlayer.onVideoResume();
|
|
|
+ super.onResume();
|
|
|
+ updateVideoCommentNo();
|
|
|
+ isPause = false;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected void onStart() {
|
|
|
- super.onStart();
|
|
|
- if (!isPauseByUser)
|
|
|
- play();
|
|
|
+ protected void onPause() {
|
|
|
+ videoPlayer.onVideoPause();
|
|
|
+ super.onPause();
|
|
|
+ isPause = true;
|
|
|
}
|
|
|
|
|
|
- //是否是用户手机暂停
|
|
|
- private boolean isPauseByUser;
|
|
|
-
|
|
|
@Override
|
|
|
- protected void onStop() {
|
|
|
- super.onStop();
|
|
|
- if (videoView != null && videoView.isPlaying())
|
|
|
- isPauseByUser = false;
|
|
|
- if (video_loading != null)
|
|
|
- video_loading.setVisibility(View.VISIBLE);
|
|
|
- pause();
|
|
|
+ public void onBackPressed() {
|
|
|
+ //释放所有
|
|
|
+ videoPlayer.setVideoAllCallBack(null);
|
|
|
+ super.onBackPressed();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
- destroy();
|
|
|
+ GSYVideoManager.releaseAllVideos();
|
|
|
super.onDestroy();
|
|
|
}
|
|
|
|
|
|
@@ -487,10 +468,9 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
LogUtil.println("mGestureListener", "Fling left", position);
|
|
|
DiscoveryVideo item = ListUtil.getItem(videoList, position);
|
|
|
if(item != null) {
|
|
|
+ ViewUtil.setVisibility(video_loading, true);
|
|
|
initVideoData(item);
|
|
|
- videoView.stopPlayback();
|
|
|
- videoView.setVideoURI(getUri());
|
|
|
- videoView.requestFocus();
|
|
|
+ changeUrl();
|
|
|
updateVideo();
|
|
|
updateVideoCommentNo();
|
|
|
}
|
|
|
@@ -505,22 +485,21 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
LogUtil.println("mGestureListener", "Fling rigth", position);
|
|
|
DiscoveryVideo item = ListUtil.getItem(videoList, position);
|
|
|
if(item != null) {
|
|
|
+ ViewUtil.setVisibility(video_loading, true);
|
|
|
initVideoData(item);
|
|
|
- videoView.stopPlayback();
|
|
|
- videoView.setVideoURI(getUri());
|
|
|
- videoView.requestFocus();
|
|
|
+ changeUrl();
|
|
|
updateVideo();
|
|
|
updateVideoCommentNo();
|
|
|
}
|
|
|
} else if (event2.getY() - event1.getY() > FLING_MIN_DISTANCE
|
|
|
&& Math.abs(velocityY) > FLING_MIN_VELOCITY) {
|
|
|
- if (direction == DIRECTION_LEFT_RIGHT) {
|
|
|
+ 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_LEFT_RIGHT) {
|
|
|
+ if (direction == DIRECTION_TOP_BOTTOM) {
|
|
|
// Fling up
|
|
|
LogUtil.println("mGestureListener", "Fling up");
|
|
|
}
|
|
|
@@ -530,49 +509,4 @@ public class ActVideoDetail extends BaseUMActivity implements MediaPlayer.OnInfo
|
|
|
}
|
|
|
|
|
|
};
|
|
|
- @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", "正在缓冲");
|
|
|
- ViewUtil.setVisibility(video_loading, true);
|
|
|
- break;
|
|
|
- case MediaPlayer.MEDIA_INFO_BUFFERING_END:
|
|
|
- case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
|
|
|
- LogUtil.println("ActPlayVideo", "onInfo", "缓冲完成");
|
|
|
- //缓存完成,继续播放
|
|
|
- ViewUtil.setVisibility(video_loading, false);
|
|
|
- ViewUtil.setVisibility(videoCoverIv, false);
|
|
|
- break;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onPrepared(MediaPlayer mediaPlayer) {
|
|
|
- LogUtil.println("ActPlayVideo", "onPrepared");
|
|
|
- mediaPlayer.start();
|
|
|
- ViewUtil.setVisibility(videoCoverIv, false);
|
|
|
- ViewUtil.setVisibility(video_loading, false);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
|
|
|
- LogUtil.println("ActPlayVideo", "onError what = " + what + " extra = " + extra);
|
|
|
- initPlay();
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCompletion(MediaPlayer mediaPlayer) {
|
|
|
- LogUtil.println("ActPlayVideo", "onCompletion");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCacheAvailable(File cacheFile, String url, int percentsAvailable) {
|
|
|
- LogUtil.println("ActPlayVideo", "onCacheAvailable", cacheFile.getAbsolutePath(), url, percentsAvailable);
|
|
|
- }
|
|
|
}
|