Ver código fonte

更新文档

杨充 4 anos atrás
pai
commit
61b0fce334

+ 6 - 4
Demo/src/main/java/org/yczbj/ycvideoplayer/BaseApplication.java

@@ -7,12 +7,10 @@ import android.util.Log;
 
 
 import com.yc.kernel.factory.PlayerFactory;
-import com.yc.kernel.impl.ijk.IjkPlayerFactory;
 import com.yc.kernel.utils.PlayerConstant;
 import com.yc.kernel.utils.PlayerFactoryUtils;
-import com.yc.kernel.utils.VideoLogUtils;
 
-import org.yczbj.ycvideoplayerlib.player.VideoPlayerConfig;
+import org.yczbj.ycvideoplayerlib.config.VideoPlayerConfig;
 import org.yczbj.ycvideoplayerlib.player.VideoViewManager;
 
 /**
@@ -61,7 +59,11 @@ public class BaseApplication extends Application {
         PlayerFactory player = PlayerFactoryUtils.getPlayer(PlayerConstant.PlayerType.TYPE_IJK);
         VideoViewManager.setConfig(VideoPlayerConfig.newBuilder()
                 .setContext(this)
-                .setLogEnabled(true)//调试的时候请打开日志,方便排错
+                //设置视频全局埋点事件
+                .setBuriedPointEvent(new BuriedPointEventImpl())
+                //调试的时候请打开日志,方便排错
+                .setLogEnabled(true)
+                //设置ijk
                 .setPlayerFactory(player)
                 .build());
     }

+ 40 - 0
Demo/src/main/java/org/yczbj/ycvideoplayer/BuriedPointEventImpl.java

@@ -0,0 +1,40 @@
+package org.yczbj.ycvideoplayer;
+
+import org.yczbj.ycvideoplayerlib.config.BuriedPointEvent;
+
+public class BuriedPointEventImpl implements BuriedPointEvent {
+    @Override
+    public void playerIn(String url) {
+
+    }
+
+    @Override
+    public void playerDestroy(String url) {
+
+    }
+
+    @Override
+    public void playerCompletion(String url) {
+
+    }
+
+    @Override
+    public void onError(String url, boolean isNetError) {
+
+    }
+
+    @Override
+    public void clickAd(String url) {
+
+    }
+
+    @Override
+    public void playerOutProgress(String url, float progress) {
+
+    }
+
+    @Override
+    public void videoToMedia(String url) {
+
+    }
+}

+ 1 - 2
Demo/src/main/java/org/yczbj/ycvideoplayer/newPlayer/activity/TypeActivity.java

@@ -30,9 +30,8 @@ import com.yc.kernel.impl.ijk.IjkVideoPlayer;
 import com.yc.kernel.impl.media.AndroidMediaPlayer;
 import com.yc.kernel.impl.media.MediaPlayerFactory;
 import com.yc.kernel.factory.PlayerFactory;
-import com.yc.kernel.inter.AbstractVideoPlayer;
 
-import org.yczbj.ycvideoplayerlib.player.VideoPlayerConfig;
+import org.yczbj.ycvideoplayerlib.config.VideoPlayerConfig;
 import org.yczbj.ycvideoplayerlib.player.VideoViewManager;
 import org.yczbj.ycvideoplayerlib.tool.BaseToast;
 import org.yczbj.ycvideoplayerlib.tool.PlayerUtils;

+ 58 - 0
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/config/BuriedPointEvent.java

@@ -0,0 +1,58 @@
+package org.yczbj.ycvideoplayerlib.config;
+
+/**
+ * <pre>
+ *     @author yangchong
+ *     blog  : https://github.com/yangchong211
+ *     time  : 2018/1/29
+ *     desc  : 视频全局埋点事件
+ *     revise:
+ * </pre>
+ */
+public interface BuriedPointEvent {
+
+    /**
+     * 进入视频播放
+     * @param url                       视频url
+     */
+    void playerIn(String url);
+
+    /**
+     * 退出视频播放
+     * @param url                       视频url
+     */
+    void playerDestroy(String url);
+
+    /**
+     * 视频播放完成
+     * @param url                       视频url
+     */
+    void playerCompletion(String url);
+
+    /**
+     * 视频播放异常
+     * @param url                       视频url
+     * @param isNetError                是否是网络异常
+     */
+    void onError(String url , boolean isNetError);
+
+    /**
+     * 点击了视频广告
+     * @param url                       视频url
+     */
+    void clickAd(String url);
+
+    /**
+     * 退出视频播放时候的播放进度百度分
+     * @param url                       视频url
+     * @param progress                  视频进度,计算百分比【退出时候进度 / 总进度】
+     */
+    void playerOutProgress(String url , float progress);
+
+    /**
+     * 视频切换音频
+     * @param url                       视频url
+     */
+    void videoToMedia(String url);
+
+}

+ 13 - 1
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/player/VideoPlayerConfig.java → VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/config/VideoPlayerConfig.java

@@ -1,4 +1,4 @@
-package org.yczbj.ycvideoplayerlib.player;
+package org.yczbj.ycvideoplayerlib.config;
 
 
 import android.content.Context;
@@ -8,6 +8,7 @@ import androidx.annotation.Nullable;
 import com.yc.kernel.factory.PlayerFactory;
 import com.yc.kernel.impl.media.MediaPlayerFactory;
 
+import org.yczbj.ycvideoplayerlib.player.ProgressManager;
 import org.yczbj.ycvideoplayerlib.surface.SurfaceFactory;
 import org.yczbj.ycvideoplayerlib.surface.TextureViewFactory;
 import org.yczbj.ycvideoplayerlib.tool.BaseToast;
@@ -40,6 +41,7 @@ public class VideoPlayerConfig {
         private boolean mEnableAudioFocus = true;
         private ProgressManager mProgressManager;
         private PlayerFactory mPlayerFactory;
+        private BuriedPointEvent mBuriedPointEvent;
         private int mScreenScaleType;
         private SurfaceFactory mRenderViewFactory;
         private boolean mAdaptCutout = true;
@@ -100,6 +102,14 @@ public class VideoPlayerConfig {
             return this;
         }
 
+        /**
+         * 自定义视频全局埋点事件
+         */
+        public Builder setBuriedPointEvent(BuriedPointEvent buriedPointEvent) {
+            mBuriedPointEvent = buriedPointEvent;
+            return this;
+        }
+
         /**
          * 设置视频比例
          */
@@ -137,6 +147,7 @@ public class VideoPlayerConfig {
     public final boolean mIsEnableLog;
     public final ProgressManager mProgressManager;
     public final PlayerFactory mPlayerFactory;
+    public final BuriedPointEvent mBuriedPointEvent;
     public final int mScreenScaleType;
     public final SurfaceFactory mRenderViewFactory;
     public final boolean mAdaptCutout;
@@ -154,6 +165,7 @@ public class VideoPlayerConfig {
         } else {
             mPlayerFactory = builder.mPlayerFactory;
         }
+        mBuriedPointEvent = builder.mBuriedPointEvent;
         if (builder.mRenderViewFactory == null) {
             //默认使用TextureView渲染视频
             mRenderViewFactory = TextureViewFactory.create();

+ 31 - 0
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/player/VideoPlayer.java

@@ -16,6 +16,7 @@ import android.view.ViewGroup;
 import android.widget.FrameLayout;
 import org.yczbj.ycvideoplayerlib.R;
 import org.yczbj.ycvideoplayerlib.config.ConstantKeys;
+import org.yczbj.ycvideoplayerlib.config.VideoPlayerConfig;
 import org.yczbj.ycvideoplayerlib.controller.BaseVideoController;
 
 import com.yc.kernel.inter.AbstractVideoPlayer;
@@ -432,6 +433,17 @@ public class VideoPlayer<P extends AbstractVideoPlayer> extends FrameLayout
      */
     public void release() {
         if (!isInIdleState()) {
+            VideoPlayerConfig config = VideoViewManager.getConfig();
+            if (config!=null && config.mBuriedPointEvent!=null){
+                //退出视频播放
+                config.mBuriedPointEvent.playerDestroy(mUrl);
+
+                //计算退出视频时候的进度
+                long duration = getDuration();
+                long currentPosition = getCurrentPosition();
+                float progress = (currentPosition*1.0f) / (duration*1.0f) ;
+                config.mBuriedPointEvent.playerOutProgress(mUrl,progress);
+            }
             //释放播放器
             if (mMediaPlayer != null) {
                 mMediaPlayer.release();
@@ -602,6 +614,15 @@ public class VideoPlayer<P extends AbstractVideoPlayer> extends FrameLayout
     public void onError() {
         mPlayerContainer.setKeepScreenOn(false);
         setPlayState(ConstantKeys.CurrentState.STATE_ERROR);
+        VideoPlayerConfig config = VideoViewManager.getConfig();
+        if (config!=null && config.mBuriedPointEvent!=null){
+            //相当于进入了视频页面
+            if (PlayerUtils.isConnected(mContext)){
+                config.mBuriedPointEvent.onError(mUrl,false);
+            } else {
+                config.mBuriedPointEvent.onError(mUrl,true);
+            }
+        }
     }
 
     /**
@@ -616,6 +637,11 @@ public class VideoPlayer<P extends AbstractVideoPlayer> extends FrameLayout
             mProgressManager.saveProgress(mUrl, 0);
         }
         setPlayState(ConstantKeys.CurrentState.STATE_BUFFERING_PLAYING);
+        VideoPlayerConfig config = VideoViewManager.getConfig();
+        if (config!=null && config.mBuriedPointEvent!=null){
+            //视频播放完成
+            config.mBuriedPointEvent.playerCompletion(mUrl);
+        }
     }
 
     @Override
@@ -712,6 +738,11 @@ public class VideoPlayer<P extends AbstractVideoPlayer> extends FrameLayout
         mAssetFileDescriptor = null;
         mUrl = url;
         mHeaders = headers;
+        VideoPlayerConfig config = VideoViewManager.getConfig();
+        if (config!=null && config.mBuriedPointEvent!=null){
+            //相当于进入了视频页面
+            config.mBuriedPointEvent.playerIn(url);
+        }
     }
 
     /**

+ 2 - 0
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/player/VideoViewManager.java

@@ -4,6 +4,8 @@ import android.app.Application;
 
 import com.yc.kernel.utils.VideoLogUtils;
 
+import org.yczbj.ycvideoplayerlib.config.VideoPlayerConfig;
+
 import java.util.LinkedHashMap;
 
 /**

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

@@ -43,7 +43,7 @@ import androidx.appcompat.app.AppCompatActivity;
 import androidx.appcompat.view.ContextThemeWrapper;
 
 import org.yczbj.ycvideoplayerlib.config.ConstantKeys;
-import org.yczbj.ycvideoplayerlib.player.VideoPlayerConfig;
+import org.yczbj.ycvideoplayerlib.config.VideoPlayerConfig;
 import org.yczbj.ycvideoplayerlib.player.VideoViewManager;
 
 import java.lang.reflect.Field;

+ 0 - 3
read/19.原生播放器问题记录.md

@@ -1,3 +0,0 @@
-# 基础方法说明
-#### 目录介绍
-

+ 4 - 0
read/29.视频播放器埋点监听.md

@@ -0,0 +1,4 @@
+# 29.视频播放器埋点监听
+#### 目录介绍
+- 01.传统一点的做饭
+- 02.如何实现统一埋点

+ 0 - 0
read/29.版本更新说明文档.md → read/32.版本更新说明文档.md


+ 0 - 0
read/30.参考项目和博客说明.md → read/33.参考项目和博客说明.md