Bläddra i källkod

修改错误异常页面添加返回键逻辑

杨充 4 år sedan
förälder
incheckning
4bfcb4e5a6

+ 1 - 1
Demo/build.gradle

@@ -69,7 +69,7 @@ dependencies {
     implementation 'cn.yc:MusicPlayer:1.0.2'
     implementation 'cn.yc:VideoPlayer:3.1.0'
     implementation 'cn.yc:VideoCache:3.0.5'
-    implementation 'cn.yc:VideoKernel:3.0.5'
+    implementation 'cn.yc:VideoKernel:3.0.6'
     implementation 'cn.yc:VideoView:3.0.5'
 
     //自己封装的库,都有对应的案例项目【欢迎star】:https://github.com/yangchong211

+ 2 - 2
README.md

@@ -124,11 +124,11 @@
 - 如下所示
     ```
     //视频UI层,必须要有
-    implementation 'cn.yc:VideoPlayer:3.0.9'
+    implementation 'cn.yc:VideoPlayer:3.1.0'
     //视频缓存,如果不需要则可以不依赖
     implementation 'cn.yc:VideoCache:3.0.5'
     //视频内核层,必须有
-    implementation 'cn.yc:VideoKernel:3.0.5'
+    implementation 'cn.yc:VideoKernel:3.0.6'
     ```
 
 #### 4.2 在xml中添加布局

+ 3 - 3
VideoKernel/build.gradle

@@ -7,8 +7,8 @@ android {
     defaultConfig {
         minSdkVersion 17
         targetSdkVersion 29
-        versionCode 30
-        versionName "3.0.0"
+        versionCode 36
+        versionName "3.0.6"
     }
 
     buildTypes {
@@ -59,7 +59,7 @@ group = "cn.yc"
 //发布到JCenter上的项目名字,必须填写
 def libName = "YCVideoKernelLib"
 // 版本号,下次更新是只需要更改版本号即可
-version = "3.0.5"
+version = "3.0.6"
 /**  上面配置后上传至jcenter后的编译路径是这样的: compile 'cn.yc:YCVideoKernelLib:1.0.0'  **/
 
 //生成源文件

+ 7 - 0
VideoKernel/src/main/java/com/yc/kernel/impl/exo/ExoMediaPlayer.java

@@ -27,6 +27,7 @@ import com.google.android.exoplayer2.util.EventLogger;
 import com.google.android.exoplayer2.util.Util;
 import com.google.android.exoplayer2.video.VideoListener;
 import com.yc.kernel.inter.AbstractVideoPlayer;
+import com.yc.kernel.inter.VideoPlayerListener;
 import com.yc.kernel.utils.PlayerConstant;
 import com.yc.kernel.utils.VideoLogUtils;
 
@@ -451,4 +452,10 @@ public class ExoMediaPlayer extends AbstractVideoPlayer implements VideoListener
             mIsPreparing = false;
         }
     }
+
+    @Override
+    public void setPlayerEventListener(VideoPlayerListener playerEventListener) {
+        super.setPlayerEventListener(playerEventListener);
+    }
+
 }

+ 5 - 0
VideoKernel/src/main/java/com/yc/kernel/impl/ijk/IjkVideoPlayer.java

@@ -26,6 +26,7 @@ import android.text.TextUtils;
 import android.view.Surface;
 import android.view.SurfaceHolder;
 import com.yc.kernel.inter.AbstractVideoPlayer;
+import com.yc.kernel.inter.VideoPlayerListener;
 import com.yc.kernel.utils.PlayerConstant;
 import com.yc.kernel.utils.VideoLogUtils;
 
@@ -481,5 +482,9 @@ public class IjkVideoPlayer extends AbstractVideoPlayer {
         }
     };
 
+    @Override
+    public void setPlayerEventListener(VideoPlayerListener playerEventListener) {
+        super.setPlayerEventListener(playerEventListener);
+    }
 
 }

+ 6 - 0
VideoKernel/src/main/java/com/yc/kernel/impl/media/AndroidMediaPlayer.java

@@ -25,6 +25,7 @@ import android.os.Build;
 import android.view.Surface;
 import android.view.SurfaceHolder;
 import com.yc.kernel.inter.AbstractVideoPlayer;
+import com.yc.kernel.inter.VideoPlayerListener;
 import com.yc.kernel.utils.PlayerConstant;
 
 import java.util.Map;
@@ -393,4 +394,9 @@ public class AndroidMediaPlayer extends AbstractVideoPlayer {
             }
         }
     };
+
+    @Override
+    public void setPlayerEventListener(VideoPlayerListener playerEventListener) {
+        super.setPlayerEventListener(playerEventListener);
+    }
 }

+ 31 - 7
VideoPlayer/src/main/java/com/yc/video/ui/view/CustomErrorView.java

@@ -15,15 +15,19 @@ limitations under the License.
 */
 package com.yc.video.ui.view;
 
+import android.app.Activity;
 import android.content.Context;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+
+import android.content.pm.ActivityInfo;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewConfiguration;
 import android.view.animation.Animation;
+import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
@@ -31,6 +35,7 @@ import com.yc.video.config.ConstantKeys;
 import com.yc.video.bridge.ControlWrapper;
 
 import com.yc.video.R;
+import com.yc.video.tool.PlayerUtils;
 
 
 /**
@@ -42,13 +47,14 @@ import com.yc.video.R;
  *     revise:
  * </pre>
  */
-public class CustomErrorView extends LinearLayout implements InterControlView {
+public class CustomErrorView extends LinearLayout implements InterControlView, View.OnClickListener {
 
     private Context mContext;
     private float mDownX;
     private float mDownY;
     private TextView mTvMessage;
     private TextView mTvRetry;
+    private ImageView mIvStopFullscreen;
 
     private ControlWrapper mControlWrapper;
 
@@ -81,16 +87,30 @@ public class CustomErrorView extends LinearLayout implements InterControlView {
     private void initFindViewById(View view) {
         mTvMessage = view.findViewById(R.id.tv_message);
         mTvRetry = view.findViewById(R.id.tv_retry);
+        mIvStopFullscreen = view.findViewById(R.id.iv_stop_fullscreen);
     }
 
     private void initListener() {
-        mTvRetry.setOnClickListener(new OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                setVisibility(GONE);
-                mControlWrapper.replay(false);
+        mTvRetry.setOnClickListener(this);
+        mIvStopFullscreen.setOnClickListener(this);
+    }
+
+
+    @Override
+    public void onClick(View v) {
+        if (v == mTvRetry){
+            setVisibility(GONE);
+            mControlWrapper.replay(false);
+        } else if (v == mIvStopFullscreen){
+            //点击返回键
+            if (mControlWrapper.isFullScreen()) {
+                Activity activity = PlayerUtils.scanForActivity(mContext);
+                if (activity != null && !activity.isFinishing()) {
+                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+                    mControlWrapper.stopFullScreen();
+                }
             }
-        });
+        }
     }
 
     @Override
@@ -113,14 +133,17 @@ public class CustomErrorView extends LinearLayout implements InterControlView {
         if (playState == ConstantKeys.CurrentState.STATE_ERROR) {
             bringToFront();
             setVisibility(VISIBLE);
+            mIvStopFullscreen.setVisibility(mControlWrapper.isFullScreen() ? VISIBLE : GONE);
             mTvMessage.setText("视频播放异常");
         } if (playState == ConstantKeys.CurrentState.STATE_NETWORK_ERROR) {
             bringToFront();
             setVisibility(VISIBLE);
+            mIvStopFullscreen.setVisibility(mControlWrapper.isFullScreen() ? VISIBLE : GONE);
             mTvMessage.setText("无网络,请检查网络设置");
         } if (playState == ConstantKeys.CurrentState.STATE_PARSE_ERROR) {
             bringToFront();
             setVisibility(VISIBLE);
+            mIvStopFullscreen.setVisibility(mControlWrapper.isFullScreen() ? VISIBLE : GONE);
             //mTvMessage.setText("视频解析异常");
             mTvMessage.setText("视频加载错误");
         } else if (playState == ConstantKeys.CurrentState.STATE_IDLE) {
@@ -165,4 +188,5 @@ public class CustomErrorView extends LinearLayout implements InterControlView {
         }
         return super.dispatchTouchEvent(ev);
     }
+
 }

+ 1 - 1
VideoPlayer/src/main/res/drawable/shape_play_bg.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <shape android:shape="oval"
        xmlns:android="http://schemas.android.com/apk/res/android">
-    <solid android:color="#9939C5BB"/>
+    <solid android:color="#323232"/>
     <size
         android:height="40dp"
         android:width="40dp"/>

+ 6 - 4
VideoPlayer/src/main/res/layout/custom_video_player_completed.xml

@@ -40,13 +40,14 @@
             android:layout_marginLeft="5dp"
             android:layout_marginRight="5dp"
             android:layout_gravity="center"
+            android:gravity="center_horizontal"
             android:orientation="vertical">
             <ImageView
                 android:id="@+id/iv_replay"
-                android:layout_width="40dp"
+                android:layout_width="100dp"
                 android:layout_height="40dp"
                 android:layout_gravity="center"
-                android:background="@drawable/shape_play_bg"
+                android:background="@drawable/bg_retry"
                 android:padding="10dp"
                 android:src="@drawable/ic_player_replay" />
             <TextView
@@ -66,13 +67,14 @@
             android:layout_marginLeft="5dp"
             android:layout_marginRight="5dp"
             android:layout_gravity="center"
+            android:gravity="center_horizontal"
             android:orientation="vertical">
             <ImageView
                 android:id="@+id/iv_share"
-                android:layout_width="40dp"
+                android:layout_width="100dp"
                 android:layout_height="40dp"
                 android:layout_gravity="center"
-                android:background="@drawable/shape_play_bg"
+                android:background="@drawable/bg_retry"
                 android:padding="10dp"
                 android:src="@drawable/ic_palyer_share" />
             <TextView

+ 21 - 1
VideoPlayer/src/main/res/layout/custom_video_player_error.xml

@@ -1,10 +1,30 @@
 <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@android:color/black">
 
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="50dp"
+        android:background="@drawable/player_mask_top"
+        android:gravity="center_vertical"
+        android:paddingTop="10dp"
+        android:paddingStart="12dp"
+        android:paddingEnd="12dp"
+        android:orientation="horizontal">
+        <ImageView
+            android:id="@+id/iv_stop_fullscreen"
+            android:layout_width="24dp"
+            android:layout_height="24dp"
+            android:background="@drawable/ic_player_back"
+            android:visibility="gone"
+            tools:visibility="visible" />
+    </LinearLayout>
+
+
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
@@ -22,7 +42,7 @@
 
         <TextView
             android:id="@+id/tv_retry"
-            android:layout_width="110dp"
+            android:layout_width="100dp"
             android:layout_height="40dp"
             android:layout_marginTop="16dp"
             android:background="@drawable/bg_retry"

+ 2 - 2
read/01.视频播放器介绍文档.md

@@ -152,11 +152,11 @@
 - 如下所示
     ```
     //视频UI层,必须要有
-    implementation 'cn.yc:VideoPlayer:3.0.9'
+    implementation 'cn.yc:VideoPlayer:3.1.0'
     //视频缓存,如果不需要则可以不依赖
     implementation 'cn.yc:VideoCache:3.0.5'
     //视频内核层,必须有
-    implementation 'cn.yc:VideoKernel:3.0.5'
+    implementation 'cn.yc:VideoKernel:3.0.6'
     ```
 
 #### 4.2 在xml中添加布局