From cd89367a01870afb5c1e818895abb03ffea42d88 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 15 十月 2020 18:25:52 +0800
Subject: [PATCH] 风行播放器完善

---
 library-mine/src/com/lcjian/library/video/VideoPlayerController.java |   78 +++++++++++++++++++++++++++++---------
 1 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/library-mine/src/com/lcjian/library/video/VideoPlayerController.java b/library-mine/src/com/lcjian/library/video/VideoPlayerController.java
index 8f09327..b056171 100644
--- a/library-mine/src/com/lcjian/library/video/VideoPlayerController.java
+++ b/library-mine/src/com/lcjian/library/video/VideoPlayerController.java
@@ -58,6 +58,7 @@
     private String videoName;
     private String videoUrl;
     private boolean collected;//鏄惁鏀惰棌
+    private String mResourceName;
 
     private Timer timer;
 
@@ -98,6 +99,8 @@
 
     //姝e湪鎾斁鐨勪綅缃�
     private int mPlayingPosition;
+
+    private int mShowType;//1-闀挎潯 2-灏忔柟鏍�
 
     private AQuery aq;
 
@@ -187,15 +190,17 @@
      *
      * @param episodeList
      * @param videoName
-     * @param videoUrl
      * @param playingPosition
      * @return
      */
-    public VideoPlayerController setVideoInfo(List<VideoEpisode> episodeList, String videoName, String videoUrl, int playingPosition) {
-        this.videoName = videoName;
-        this.videoUrl = videoUrl;
+    public VideoPlayerController setVideoInfo(List<VideoEpisode> episodeList, int playingPosition, int showType, String resourceName) {
+        VideoEpisode currentVideoEpisode = episodeList.get(playingPosition);
+        this.videoName = currentVideoEpisode.getName();
+        this.videoUrl = currentVideoEpisode.getVideoUrl();
         this.episodeList = episodeList;
         this.mPlayingPosition = playingPosition;
+        this.mShowType = showType;
+        this.mResourceName = resourceName;
         return this;
     }
 
@@ -262,6 +267,7 @@
                                     VideoPlayerController.this.continuePlay();
                                     //涓嶉渶瑕佹彁閱�
                                     needNotifyMobileData = false;
+                                    setPlayImage();
                                 }
 
                                 @Override
@@ -271,6 +277,8 @@
                             }).build(mActivity);
                         if (!networkNotiftDialog.isShowing())
                             networkNotiftDialog.show();
+                    } else {
+                        continuePlay();
                     }
                     break;
                 case ConnectivityManager.TYPE_WIFI:
@@ -286,7 +294,30 @@
             pausePlay();
         }
 
+        //璁剧疆鎾斁鎸夐挳鐨勭姸鎬佹寜閽殑
+        setPlayImage();
     }
+
+    private void setPlayImage() {
+        if (iv_play != null)
+            iv_play.postDelayed(new Runnable() {
+                @Override
+                public void run() {
+                    if (mediaPlayer == null) {
+                        return;
+                    }
+                    VideoResourceUtil.setPlayImage(iv_play, mediaPlayer.isPlaying(), isLand);
+                    if (mediaPlayer.isPlaying()) {
+                        aq.id(R.id.iv_play_center).visibility(View.GONE);
+                    } else {
+                        if (!isLand) {
+                            aq.id(R.id.iv_play_center).visibility(View.VISIBLE);
+                        }
+                    }
+                }
+            }, 100);
+    }
+
 
     /**
      * 璁剧疆鐢甸噺鍙樺寲
@@ -362,7 +393,10 @@
         public void onProgressChanged(SeekBar seekBar, int precent, boolean b) {
             if (isTouch) {
                 //璁$畻  鎷栨媺鍚庣殑  鏃堕棿闀垮害锛�
-                int positionLong = mediaPlayer.getDuration() * seekBar.getProgress() / 1000;
+                int process = mediaPlayer.getDuration();
+                float f = seekBar.getProgress() / 1000.0f;
+                int positionLong = (int) (process * f);
+                Log.i(TAG, "position:" + positionLong);
                 mediaPlayer.seekTo(positionLong);
             }
 
@@ -395,6 +429,7 @@
         setLayout();
         tv_title.setText(videoName);
         tv_link.setText(videoUrl);
+        tv_resource.setText("鏉ユ簮锛�" + mResourceName);
         setCollect(this.collected);
 
         showLoading();
@@ -437,7 +472,7 @@
             @Override
             public void onClick(View v) {
                 //褰撳墠闆�
-                episodeDialog = new VideoEpisodeDialog.Builder().setEpisodes(episodeList, mPlayingPosition, 1).setDialogClick(new VideoEpisodeDialog.IDialogClick() {
+                episodeDialog = new VideoEpisodeDialog.Builder().setEpisodes(episodeList, mPlayingPosition, mShowType).setDialogClick(new VideoEpisodeDialog.IDialogClick() {
                     @Override
                     public void selectEpisode(int p, VideoEpisode ve) {
                         if (videoPlayerListener != null)
@@ -464,11 +499,10 @@
                 if (mediaPlayer != null) {
                     if (mediaPlayer.isPlaying()) {
                         mediaPlayer.pause();
-                        VideoResourceUtil.setPlayImage(iv_play, true, isLand);
                     } else {
                         mediaPlayer.start();
-                        VideoResourceUtil.setPlayImage(iv_play, false, isLand);
                     }
+                    setPlayerState();
                 }
             }
         });
@@ -621,6 +655,7 @@
     }
 
     private void setLayout() {
+        Log.i(TAG, "setLayout");
         if (isLand) {
             findViewById(R.id.fl_state).setVisibility(View.VISIBLE);
 //            if (iv_collection.getVisibility() == View.GONE)
@@ -684,8 +719,13 @@
             if (mediaPlayer != null && mediaPlayer.isPlaying()) {
                 int currentPosition = getSeconds(mediaPlayer.getCurrentPosition());
                 tv_progress.setText(TimeUtil.getTimeDesc(currentPosition));
-                seekBar.setProgress(Math.round(mediaPlayer.getCurrentPosition() * 1000 / mediaPlayer.getDuration()));
-                setPlayerState();
+                seekBar.setProgress(Math.round(mediaPlayer.getCurrentPosition() * 1000.0f / mediaPlayer.getDuration()));
+                Log.i(TAG, Math.abs(mediaPlayer.getDuration() - mediaPlayer.getCurrentPosition()) + "");
+                if (Math.abs(mediaPlayer.getDuration() - mediaPlayer.getCurrentPosition()) < 1000) {//鎾斁瀹屾垚
+                    tv_progress.removeCallbacks(playerProcessRunnable);
+                    iv_next.performClick();
+                    return;
+                }
             }
             tv_progress.postDelayed(playerProcessRunnable, 1000);
         }
@@ -729,15 +769,7 @@
 
     private void setPlayerState() {
         if (mediaPlayer != null) {
-            if (mediaPlayer.isPlaying()) {
-                VideoResourceUtil.setPlayImage(iv_play, false, isLand);
-                aq.id(R.id.iv_play_center).visibility(View.GONE);
-            } else {
-                VideoResourceUtil.setPlayImage(iv_play, true, isLand);
-                if (!isLand) {
-                    aq.id(R.id.iv_play_center).visibility(View.VISIBLE);
-                }
-            }
+            setPlayImage();
         }
     }
 
@@ -817,6 +849,14 @@
         aq.id(R.id.fl_loading).visibility(View.GONE);
     }
 
+    public void onResume() {
+        setLayout();
+    }
+
+    public void onPause() {
+        setLayout();
+    }
+
     /**
      * 閲婃斁璧勬簮
      */

--
Gitblit v1.8.0