소스 검색

可以直接在游戏详情中进行宣传图视频的播放

zengjiebin 7 년 전
부모
커밋
75a92bf982

+ 5 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/Applications.java

@@ -514,4 +514,9 @@ public class Applications implements IDownload, IGameGroup, Serializable {
     public boolean hasGameDiscountId() {
         return game_discount_id > 0;
     }
+
+    //主宣传图是视频
+    public boolean mainPublicizeIsVideo() {
+        return main_publicize.endsWith(".mp4") || main_publicize.startsWith("http://cdn.video.17xmy.com");//如:http://cdn.video.17xmy.com/ljok9RZZvXc5qwvoCxEGudchO6Ti;
+    }
 }

+ 136 - 15
app/src/main/java/com/sheep/gamegroup/module/game/activity/ActGameGroupOrGameDetail.java

@@ -31,6 +31,7 @@ import com.sheep.gamegroup.model.entity.Applications;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.GameEntity;
 import com.sheep.gamegroup.model.entity.GameListTag;
+import com.sheep.gamegroup.model.entity.Lp;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.module.game.adapter.AdpGameGroupGameCompare;
 import com.sheep.gamegroup.module.game.fragment.FgtGameComment;
@@ -46,12 +47,17 @@ import com.sheep.gamegroup.util.RefreshUtil;
 import com.sheep.gamegroup.util.RequestCodeConstants;
 import com.sheep.gamegroup.util.TagListUtil;
 import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.gamegroup.util.viewHelper.LayoutParamsUtil;
 import com.sheep.gamegroup.view.activity.ActPlayVideo;
 import com.sheep.gamegroup.view.adapter.TitleFragmentListAdapter2;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
+import com.shuyu.gsyvideoplayer.GSYVideoManager;
+import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
+import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
+import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
 
 import org.afinal.simplecache.ApiKey;
 import org.greenrobot.eventbus.EventBus;
@@ -83,7 +89,9 @@ public class ActGameGroupOrGameDetail extends BaseActivity {
         StatusBarUtils.setTranslucent(this);
         super.onCreate(savedInstanceState);
     }
+
     public static final String AUTO_DOWNLOAD = "auto_download";//自动下载的标识
+
     @Override
     protected int getLayoutId() {
         return R.layout.act_game_group_or_game_detail;
@@ -99,6 +107,8 @@ public class ActGameGroupOrGameDetail extends BaseActivity {
     ImageView gc_game_app_detail_iv;
     @BindView(R.id.gc_game_app_detail_iv2)
     ImageView gc_game_app_detail_iv2;
+    @BindView(R.id.detail_player)
+    StandardGSYVideoPlayer videoPlayer;
     @BindView(R.id.gc_game_app_detail_play_iv)
     ImageView gc_game_app_detail_play_iv;
     @BindView(R.id.gc_game_app_detail_icon)
@@ -188,14 +198,14 @@ public class ActGameGroupOrGameDetail extends BaseActivity {
         ViewUtil.setVisibility(item_gc_game_app_list_top, isGameGroupNull);
         ViewUtil.setVisibility(gc_game_app_detail_bt2, isGameGroupNull);
         ViewUtil.setVisibility(gc_game_app_detail_line, isGameGroupNull);
-        if(isGameGroupNull){
+        if (isGameGroupNull) {
         } else {//游戏组,不显示下载按钮
             ViewUtil.setText(item_gc_game_app_list_tv, "比一比");
             item_gc_game_app_list_rv.setHasFixedSize(true);
             item_gc_game_app_list_rv.setNestedScrollingEnabled(false);
             item_gc_game_app_list_rv.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
-            if(!ListUtil.isEmpty(gameGroup.getApplications())) {
-                if(AdpGameGroupGameCompare.canDownload) {
+            if (!ListUtil.isEmpty(gameGroup.getApplications())) {
+                if (AdpGameGroupGameCompare.canDownload) {
                     for (Applications item : gameGroup.getApplications()) {
                         applicationsMap.put(item.getDownload_link(), item);
                         applicationsMap.put(item.getPackage_name(), item);
@@ -256,18 +266,27 @@ public class ActGameGroupOrGameDetail extends BaseActivity {
         //加载游戏背景
         if (TextUtils.isEmpty(mainBublicize)) {
             ViewUtil.setImage(gc_game_app_detail_iv, gameEntity.getApp().getPictures());
+            ViewUtil.setVisibility(videoPlayer, false);
             ViewUtil.setVisibility(gc_game_app_detail_iv, true);
             ViewUtil.setVisibility(gc_game_app_detail_iv2, false);
-        } else {
+
+            ViewUtil.setVisibility(gc_game_app_detail_play_iv, false);
+        } else if (gameEntity.getApp().mainPublicizeIsVideo()) {
+            ViewUtil.setVisibility(videoPlayer, false);
             ViewUtil.setVisibility(gc_game_app_detail_iv, false);
             ViewUtil.setVisibility(gc_game_app_detail_iv2, true);
-            if (mainBublicize.endsWith(".mp4") || mainBublicize.startsWith("http://cdn.video.17xmy.com")) {//如:http://cdn.video.17xmy.com/ljok9RZZvXc5qwvoCxEGudchO6Ti
-                ViewUtil.setImage(gc_game_app_detail_iv2, ActPlayVideo.getCoverByUrl(mainBublicize));
-                gc_game_app_detail_play_iv.setVisibility(View.VISIBLE);
-                gc_game_app_detail_play_iv.setOnClickListener(view -> Jump2View.getInstance().goActPlayVideo(mainBublicize, gameEntity.getApp().getName()));
-            } else {//否则当做图片显示
-                ViewUtil.setImage(gc_game_app_detail_iv2, mainBublicize);
-            }
+            ViewUtil.setImage(gc_game_app_detail_iv2, ActPlayVideo.getCoverByUrl(mainBublicize));
+            //播放按钮
+            ViewUtil.setVisibility(gc_game_app_detail_play_iv, true);
+            gc_game_app_detail_play_iv.setOnClickListener(view -> loadVideo());
+        } else {//否则当做图片显示
+            ViewUtil.setVisibility(videoPlayer, false);
+            ViewUtil.setVisibility(gc_game_app_detail_iv, false);
+            ViewUtil.setVisibility(gc_game_app_detail_iv2, true);
+
+            ViewUtil.setVisibility(gc_game_app_detail_play_iv, false);
+
+            ViewUtil.setImage(gc_game_app_detail_iv2, mainBublicize);
         }
         //加载游戏图标
         ViewUtil.setGameImage(gc_game_app_detail_icon, gameEntity.getApp().getIcon());
@@ -288,12 +307,13 @@ public class ActGameGroupOrGameDetail extends BaseActivity {
         fgtGameDetail.loadData(gameEntity);
         ViewUtil.setVisibility(gc_game_app_detail_bt3, gameEntity.getApp().hasGameDiscountId());
 
-        if(isAutoDownload){//可以进行自动下载
-            if(!PackageUtil.isAppInstalled(SheepApp.getInstance(), gameEntity.getApp().getPackage_name())) {//未安装的情况才进行下载
+        if (isAutoDownload) {//可以进行自动下载
+            if (!PackageUtil.isAppInstalled(SheepApp.getInstance(), gameEntity.getApp().getPackage_name())) {//未安装的情况才进行下载
                 gc_game_app_detail_bt2.performLongClick();
             }
         }
     }
+
     //更新评分
     public void updateScore(float score) {
         int progress = (int) score;
@@ -490,17 +510,18 @@ public class ActGameGroupOrGameDetail extends BaseActivity {
             return item != null ? item.getDownloadHelper() : null;
         }
     };
+
     @Subscribe
     public void onEventMainThread(Intent intent) {
         absGetDownloadListener.onEventMainThread(intent);
-        if(AdpGameGroupGameCompare.canDownload)
+        if (AdpGameGroupGameCompare.canDownload)
             absGetDownloadListener2.onEventMainThread(intent);
     }
 
     @Subscribe
     public void onEventMainThread(BigEvent event) {
         absGetDownloadListener.onEventMainThread(event);
-        if(AdpGameGroupGameCompare.canDownload)
+        if (AdpGameGroupGameCompare.canDownload)
             absGetDownloadListener2.onEventMainThread(event);
     }
 
@@ -517,8 +538,108 @@ public class ActGameGroupOrGameDetail extends BaseActivity {
 
     @Override
     protected void onDestroy() {
+        GSYVideoManager.releaseAllVideos();
         super.onDestroy();
         EventBus.getDefault().unregister(this);
     }
 
+    private void loadVideo() {
+        ViewUtil.setVisibility(videoPlayer, true);
+        //不显示播放按钮
+        ViewUtil.setVisibility(gc_game_app_detail_play_iv, false);
+        video_url = gameEntity.getApp().getMain_publicize();
+        video_title = gameEntity.getApp().getName();
+        video_cover_url = ActPlayVideo.getCoverByUrl(gameEntity.getApp().getMain_publicize());
+        LayoutParamsUtil.resetLayoutParams(videoPlayer, new Lp().setHeight(gc_game_app_detail_iv2.getHeight()));
+        initPlay();
+    }
+
+    private String video_url;
+    private String video_cover_url;
+    private String video_title;
+
+    private String getVideoUrl() {
+        return video_url;
+    }
+
+    private String getVideoCoverUrl() {
+        return video_cover_url;
+    }
+
+    private String getVideoTitle() {
+        return video_title;
+    }
+
+    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);
+                            isPlay = true;
+                        }
+
+                        @Override
+                        public void onAutoComplete(String url, Object... objects) {
+                            super.onAutoComplete(url, objects);
+                            if (videoPlayer != null)
+                                videoPlayer.startPlayLogic();
+                        }
+                    }).build(videoPlayer);
+            isInit = true;
+        } else {
+            videoPlayer.setUp(getVideoUrl(), true, getVideoTitle());
+        }
+        if (videoPlayer != null) {
+            videoPlayer.startPlayLogic();
+            ViewUtil.setVisibility(videoPlayer.getThumbImageViewLayout(), true);
+            ViewUtil.setVisibility2(videoPlayer.getTitleTextView(), false);
+            ViewUtil.setVisibility2(videoPlayer.getBackButton(), false);
+            if (videoPlayer.getFullscreenButton() != null)
+                videoPlayer.getFullscreenButton().setOnClickListener(v -> Jump2View.getInstance().goActPlayVideo(video_url, video_title, video_cover_url));//跳转播放
+        }
+        ViewUtil.setImage(coverImageView, getVideoCoverUrl());
+    }
+
+    @Override
+    protected void onResume() {
+        if (videoPlayer != null)
+            videoPlayer.onVideoResume();
+        super.onResume();
+        isPlay = true;
+    }
+
+    @Override
+    protected void onPause() {
+        if (videoPlayer != null)
+            videoPlayer.onVideoPause();
+        super.onPause();
+        isPlay = false;
+    }
+
+    @Override
+    public void onBackPressed() {
+        //释放所有
+        if (videoPlayer != null)
+            videoPlayer.setVideoAllCallBack(null);
+        super.onBackPressed();
+    }
 }

+ 6 - 1
app/src/main/res/layout/act_game_group_or_game_detail.xml

@@ -69,7 +69,12 @@
                         android:scaleType="fitXY"
                         android:src="@drawable/loading_01"
                         android:visibility="gone" />
-
+                    <com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
+                        android:id="@+id/detail_player"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:minHeight="100dp"
+                        android:visibility="gone"/>
                     <ImageView
                         android:layout_width="?attr/actionBarSize"
                         android:layout_height="?attr/actionBarSize"