Browse Source

完善异常信息的暴露

杨充 4 năm trước cách đây
mục cha
commit
bac67a8fd4

+ 10 - 3
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/player/VideoPlayer.java

@@ -541,8 +541,15 @@ public class VideoPlayer<P extends AbstractVideoPlayer> extends FrameLayout
      */
     @Override
     public void seekTo(long pos) {
+        long seek;
+        if (pos<0){
+            VideoLogUtils.d("设置参数-------设置开始跳转播放位置不能小于0");
+            seek = 0;
+        } else {
+            seek = pos;
+        }
         if (isInPlaybackState()) {
-            mMediaPlayer.seekTo(pos);
+            mMediaPlayer.seekTo(seek);
         }
     }
 
@@ -739,7 +746,7 @@ public class VideoPlayer<P extends AbstractVideoPlayer> extends FrameLayout
      */
     public void setPlayerFactory(PlayerFactory<P> playerFactory) {
         if (playerFactory == null) {
-            throw new IllegalArgumentException("PlayerFactory can not be null!");
+            throw new VideoException(VideoException.CODE_NOT_PLAYER_FACTORY,"PlayerFactory can not be null!");
         }
         mPlayerFactory = playerFactory;
     }
@@ -749,7 +756,7 @@ public class VideoPlayer<P extends AbstractVideoPlayer> extends FrameLayout
      */
     public void setRenderViewFactory(SurfaceFactory renderViewFactory) {
         if (renderViewFactory == null) {
-            throw new IllegalArgumentException("RenderViewFactory can not be null!");
+            throw new VideoException(VideoException.CODE_NOT_RENDER_FACTORY,"RenderViewFactory can not be null!");
         }
         mRenderViewFactory = renderViewFactory;
     }

+ 6 - 1
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/tool/VideoException.java

@@ -6,7 +6,7 @@ package org.yczbj.ycvideoplayerlib.tool;
  *     blog  : https://github.com/yangchong211
  *     time  : 2018/11/9
  *     desc  : 播放器异常
- *     revise:
+ *     revise: 抛出异常并且供开发者快捷查询异常定位代码
  * </pre>
  */
 public class VideoException extends RuntimeException {
@@ -18,6 +18,7 @@ public class VideoException extends RuntimeException {
         mCode = code;
     }
 
+    @Deprecated
     public VideoException(String msg) {
         super(msg);
     }
@@ -37,6 +38,10 @@ public class VideoException extends RuntimeException {
         return getMessage();
     }
 
+    //自定义RenderView不能设置为null
+    public static final int CODE_NOT_RENDER_FACTORY = 19;
+    //PlayerFactory不能设置为null
+    public static final int CODE_NOT_PLAYER_FACTORY = 20;
     //VideoPlayer,需要在start播放前给设置控制器Controller
     public static final int CODE_NOT_SET_CONTROLLER = 21;