Browse Source

添加了视频播放时,底部显示播放进度的逻辑功能

yangchong211 6 years ago
parent
commit
06daa6e7e1

+ 1 - 1
.idea/misc.xml

@@ -29,7 +29,7 @@
       </value>
     </option>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

+ 9 - 1
YCVideoPlayerLib/src/main/java/org/yczbj/ycvideoplayerlib/controller/VideoPlayerController.java

@@ -99,6 +99,8 @@ public class VideoPlayerController extends AbsVideoPlayerController implements V
     private TextView mShare;
     private FrameLayout mFlLock;
     private ImageView mIvLock;
+    private LinearLayout mLine;
+    private ProgressBar mPbPlayBar;
 
     private boolean topBottomVisible;
     /**
@@ -309,11 +311,13 @@ public class VideoPlayerController extends AbsVideoPlayerController implements V
         mFlLock = findViewById(R.id.fl_lock);
         mIvLock = findViewById(R.id.iv_lock);
 
+        mLine = findViewById(R.id.line);
+        mPbPlayBar = findViewById(R.id.pb_play_bar);
+
         setTopVisibility(mIsTopAndBottomVisibility);
     }
 
 
-
     private void initListener() {
         mCenterStart.setOnClickListener(this);
         mBack.setOnClickListener(this);
@@ -747,6 +751,7 @@ public class VideoPlayerController extends AbsVideoPlayerController implements V
         cancelDismissTopBottomTimer();
         mSeek.setProgress(0);
         mSeek.setSecondaryProgress(0);
+        mPbPlayBar.setProgress(0);
         mCenterStart.setVisibility(VISIBLE);
         mLength.setVisibility(View.VISIBLE);
         mFlLock.setVisibility(View.GONE);
@@ -908,6 +913,7 @@ public class VideoPlayerController extends AbsVideoPlayerController implements V
     private void setTopBottomVisible(boolean visible) {
         mTop.setVisibility(visible ? View.VISIBLE : View.GONE);
         mBottom.setVisibility(visible ? View.VISIBLE : View.GONE);
+        mLine.setVisibility(visible ? View.GONE : View.VISIBLE);
         topBottomVisible = visible;
         if (visible) {
             if (!mVideoPlayer.isPaused() && !mVideoPlayer.isBufferingPaused()) {
@@ -1008,6 +1014,7 @@ public class VideoPlayerController extends AbsVideoPlayerController implements V
         mSeek.setSecondaryProgress(bufferPercentage);
         int progress = (int) (100f * position / duration);
         mSeek.setProgress(progress);
+        mPbPlayBar.setProgress(progress);
         mPosition.setText(VideoPlayerUtils.formatTime(position));
         mDuration.setText(VideoPlayerUtils.formatTime(duration));
         // 更新时间
@@ -1029,6 +1036,7 @@ public class VideoPlayerController extends AbsVideoPlayerController implements V
         mChangePositionCurrent.setText(VideoPlayerUtils.formatTime(newPosition));
         mChangePositionProgress.setProgress(newPositionProgress);
         mSeek.setProgress(newPositionProgress);
+        mPbPlayBar.setProgress(newPositionProgress);
         mPosition.setText(VideoPlayerUtils.formatTime(newPosition));
     }
 

+ 3 - 1
YCVideoPlayerLib/src/main/java/org/yczbj/ycvideoplayerlib/view/VideoSurfaceView.java

@@ -62,7 +62,9 @@ public class VideoSurfaceView extends SurfaceView {
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         float viewRotation = getRotation();
         // 如果判断成立,则说明显示的TextureView和本身的位置是有90度的旋转的,所以需要交换宽高参数。
-        if (viewRotation == 90f || viewRotation == 270f) {
+        float viewRotation1 = 90f;
+        float viewRotation2 = 270f;
+        if (viewRotation == viewRotation1 || viewRotation == viewRotation2) {
             int tempMeasureSpec = widthMeasureSpec;
             //noinspection SuspiciousNameCombination
             widthMeasureSpec = heightMeasureSpec;

+ 5 - 1
YCVideoPlayerLib/src/main/java/org/yczbj/ycvideoplayerlib/window/IFloatWindowImpl.java

@@ -30,7 +30,7 @@ public class IFloatWindowImpl extends IFloatWindow {
     IFloatWindowImpl(FloatWindow.B b) {
         mB = b;
         if (mB.mMoveType == MoveType.fixed) {
-            if (Build.VERSION.SDK_INT >=25) {
+            if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.N_MR1) {
                 mFloatView = new FloatPhone(b.mApplicationContext);
             } else {
                 mFloatView = new FloatToast(b.mApplicationContext);
@@ -211,8 +211,12 @@ public class IFloatWindowImpl extends IFloatWindow {
                                         });
                                         startAnimator();
                                         break;
+                                        default:
+                                            break;
                                 }
                                 break;
+                                default:
+                                    break;
 
                         }
                         return false;

+ 0 - 0
YCVideoPlayerLib/src/main/res/drawable-xhdpi/ic_back_white.png → YCVideoPlayerLib/src/main/res/drawable-xhdpi/ic_player_back.png


+ 15 - 0
YCVideoPlayerLib/src/main/res/drawable/progress_bar_style.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:id="@android:id/background">
+        <shape>
+            <solid android:color="@android:color/transparent" />
+        </shape>
+    </item>
+    <item android:id="@android:id/progress">
+        <clip>
+            <shape>
+                <solid android:color="@color/redTab" />
+            </shape>
+        </clip>
+    </item>
+</layer-list>

+ 3 - 0
YCVideoPlayerLib/src/main/res/layout/custom_video_player.xml

@@ -71,4 +71,7 @@
             android:src="@drawable/player_unlock_btn"/>
     </FrameLayout>
 
+    <!--底部视频播放进度条-->
+    <include layout="@layout/custom_video_player_line"/>
+
 </RelativeLayout>

+ 17 - 0
YCVideoPlayerLib/src/main/res/layout/custom_video_player_line.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/line"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:layout_alignParentBottom="true">
+
+    <ProgressBar
+        android:id="@+id/pb_play_bar"
+        style="?android:attr/progressBarStyleHorizontal"
+        android:layout_width="match_parent"
+        android:layout_height="2dp"
+        android:layout_gravity="bottom"
+        android:progressDrawable="@drawable/progress_bar_style" />
+
+</LinearLayout>

+ 3 - 3
YCVideoPlayerLib/src/main/res/layout/custom_video_player_top.xml

@@ -12,9 +12,9 @@
 
     <ImageView
         android:id="@+id/back"
-        android:layout_width="22dp"
-        android:layout_height="22dp"
-        android:background="@drawable/ic_back_white"
+        android:layout_width="24dp"
+        android:layout_height="24dp"
+        android:background="@drawable/ic_player_back"
         android:visibility="visible"/>
     <TextView
         android:id="@+id/title"

+ 1 - 0
YCVideoPlayerLib/src/main/res/values/colors.xml

@@ -2,4 +2,5 @@
 <resources>
     <color name="dialog_bg">#bc000000</color>
     <color name="alpha_25_black">#40000000</color>
+    <color name="redTab">#D03E49</color>
 </resources>

+ 2 - 2
app/build.gradle

@@ -85,7 +85,7 @@ dependencies {
     compile 'cn.yc:YCBaseAdapterLib:1.3'                            //adapter封装
     compile 'cn.yc:YCDialogLib:3.5'                                 //弹窗
     compile 'cn.yc:YCProgressLib:1.2'                               //进度条
-    compile 'cn.yc:YCVideoPlayerLib:2.6.1'                            //播放器
-//    compile project(':YCVideoPlayerLib')
+//    compile 'cn.yc:YCVideoPlayerLib:2.6.1'                            //播放器
+    compile project(':YCVideoPlayerLib')
     compile 'cn.yc:YCStatusBarLib:1.4.0'                              //状态栏
 }

+ 1 - 1
app/src/main/res/layout/base_tool_bar.xml

@@ -37,7 +37,7 @@
             android:layout_width="18dp"
             android:layout_height="28dp"
             android:layout_gravity="center"
-            android:src="@drawable/ic_back_white" />
+            android:src="@drawable/ic_player_back" />
     </FrameLayout>
 
     <!--中间标题-->

+ 23 - 0
read/wiki1.md

@@ -16,3 +16,26 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 59 - 0
read/wiki2.md

@@ -10,6 +10,7 @@
 - 08.关于网络状态监听优化
 - 09.关于代码规范优化
 - 10.关于布局优化
+- 11.选择SurfaceView还是TextureView
 
 
 
@@ -180,6 +181,64 @@
     - 视频播放错误时状态布局
     - 会员权限等布局,非会员时显示布局
     - 全屏播放时的布局
+- 建议这样写,不要在一个布局写这么复杂的布局,这里充分体现了include的优势
+    ```
+    <?xml version="1.0" encoding="utf-8"?>
+    <RelativeLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <!--https://github.com/yangchong211-->
+        <!--如果你觉得好,请给个star,让更多人使用,避免重复造轮子-->
+        <!--底图,主要是显示视频缩略图-->
+        <ImageView
+            android:id="@+id/image"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:scaleType="fitXY"
+            android:visibility="visible"/>
+        <!--加载动画view-->
+        <include layout="@layout/custom_video_player_loading"/>
+        <!--改变播放位置-->
+        <include layout="@layout/custom_video_player_change_position"/>
+        <!--改变亮度-->
+        <include layout="@layout/custom_video_player_change_brightness"/>
+        <!--改变声音-->
+        <include layout="@layout/custom_video_player_change_volume"/>
+        <!--播放完成,你也可以自定义-->
+        <include layout="@layout/custom_video_player_completed"/>
+        <!--播放错误-->
+        <include layout="@layout/custom_video_player_error"/>
+        <!--顶部控制区-->
+        <include layout="@layout/custom_video_player_top"/>
+        <!--底部控制区-->
+        <include layout="@layout/custom_video_player_bottom"/>
+
+        //这里省略部分代码
+    </RelativeLayout>
+    ```
+
+
+
+### 11.选择SurfaceView还是TextureView
+#### 11.1 SurfaceView优缺点
+- 优点:
+    - 可以在一个独立的线程中进行绘制,不会影响主线程;使用双缓冲机制,播放视频时画面更流畅
+- 缺点:
+    - Surface不在View hierachy中,它的显示也不受View的属性控制,所以不能进行平移,缩放等变换,也不能放在其它ViewGroup中。SurfaceView 不能嵌套使用。
+
+
+#### 11.2 TextureView优缺点
+- 优点:
+    - 支持移动、旋转、缩放等动画,支持截图。具有view的属性
+- 缺点:
+    - 必须在硬件加速的窗口中使用,占用内存比SurfaceView高,在5.0以前在主线程渲染,5.0以后有单独的渲染线程。
+
+
+
+#### 11.3 作为视频播放器如何选择
+