Pārlūkot izejas kodu

完善原生demo

杨充 4 gadi atpakaļ
vecāks
revīzija
4497b37ec9

+ 7 - 3
Demo/build.gradle

@@ -61,9 +61,13 @@ dependencies {
     //自己封装的库,都有对应的案例项目【欢迎star】:https://github.com/yangchong211
     implementation 'cn.yc:YCStateLib:1.1'                                  //状态管理
 //    implementation 'cn.yc:YCVideoPlayerLib:2.6.6'                            //播放器
-    implementation project(':VideoCache')
-    implementation project(':VideoPlayer')
-    implementation project(':VideoKernel')
+//    implementation project(':VideoCache')
+//    implementation project(':VideoPlayer')
+//    implementation project(':VideoKernel')
+
+    implementation 'cn.yc:VideoPlayer:3.0.1'
+    implementation 'cn.yc:VideoCache:3.0.0'
+    implementation 'cn.yc:VideoKernel:3.0.0'
     implementation 'cn.yc:YCStatusBarLib:1.4.0'
  //状态栏
 }

+ 5 - 1
Demo/src/main/java/org/yczbj/ycvideoplayer/BaseApplication.java

@@ -6,7 +6,10 @@ import android.content.res.Configuration;
 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;
@@ -55,10 +58,11 @@ public class BaseApplication extends Application {
         ScreenDensityUtils.register(this,375.0f,
                 ScreenDensityUtils.MATCH_BASE_WIDTH,ScreenDensityUtils.MATCH_UNIT_DP);
         //播放器配置,注意:此为全局配置,按需开启
+        PlayerFactory player = PlayerFactoryUtils.getPlayer(PlayerConstant.PlayerType.TYPE_IJK);
         VideoViewManager.setConfig(VideoPlayerConfig.newBuilder()
                 .setContext(this)
                 .setLogEnabled(true)//调试的时候请打开日志,方便排错
-                .setPlayerFactory(IjkPlayerFactory.create())
+                .setPlayerFactory(player)
                 .build());
     }
 

+ 6 - 1
README.md

@@ -127,7 +127,12 @@
 #### 4.1 关于gradle引用说明
 - 如下所示
     ```
-    
+    //视频UI层,必须要有
+    implementation 'cn.yc:VideoPlayer:3.0.0'
+    //视频缓存,如果不需要则可以不依赖
+    implementation 'cn.yc:VideoCache:3.0.0'
+    //视频内核层,必须有
+    implementation 'cn.yc:VideoKernel:3.0.0'
     ```
 
 #### 4.2 在xml中添加布局

+ 3 - 3
VideoCache/build.gradle

@@ -7,8 +7,8 @@ android {
     defaultConfig {
         minSdkVersion 17
         targetSdkVersion 29
-        versionCode 1
-        versionName "1.0"
+        versionCode 30
+        versionName "3.0.0"
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         consumerProguardFiles "consumer-rules.pro"
@@ -41,7 +41,7 @@ group = "cn.yc"
 //发布到JCenter上的项目名字,必须填写
 def libName = "YCVideoCacheLib"
 // 版本号,下次更新是只需要更改版本号即可
-version = "1.0.1"
+version = "3.0.0"
 /**  上面配置后上传至jcenter后的编译路径是这样的: compile 'cn.yc:YCVideoCacheLib:1.0.0'  **/
 
 //生成源文件

+ 11 - 11
VideoKernel/build.gradle

@@ -7,8 +7,8 @@ android {
     defaultConfig {
         minSdkVersion 17
         targetSdkVersion 29
-        versionCode 1
-        versionName "1.0"
+        versionCode 30
+        versionName "3.0.0"
     }
 
     buildTypes {
@@ -22,8 +22,8 @@ android {
 dependencies {
     implementation fileTree(dir: "libs", include: ["*.jar"])
     //这两个是必须要加的,其它的可供选择
-    implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
-    implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4'
+    api 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
+    api 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4'
     //其他库文件
     //implementation 'tv.danmaku.ijk.media:ijkplayer-armv5:0.8.8'
     //implementation 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8'
@@ -32,16 +32,16 @@ dependencies {
 
 
     //谷歌播放器
-    implementation  "com.google.android.exoplayer:exoplayer:2.11.3"
+    api  "com.google.android.exoplayer:exoplayer:2.11.3"
     //exoplayer-core:核心功能 (必要)
-    implementation "com.google.android.exoplayer:exoplayer-core:2.11.3"
+    api "com.google.android.exoplayer:exoplayer-core:2.11.3"
     //exoplayer-dash:支持DASH内容
-    implementation "com.google.android.exoplayer:exoplayer-dash:2.11.3"
+    api "com.google.android.exoplayer:exoplayer-dash:2.11.3"
     //exoplayer-hls:支持HLS内容
-    implementation "com.google.android.exoplayer:exoplayer-hls:2.11.3"
+    api "com.google.android.exoplayer:exoplayer-hls:2.11.3"
     //exoplayer-smoothstreaming:支持SmoothStreaming内容
-    implementation "com.google.android.exoplayer:exoplayer-smoothstreaming:2.11.3"
-    implementation "com.google.android.exoplayer:extension-rtmp:2.11.3"
+    api "com.google.android.exoplayer:exoplayer-smoothstreaming:2.11.3"
+    api "com.google.android.exoplayer:extension-rtmp:2.11.3"
 }
 
 
@@ -59,7 +59,7 @@ group = "cn.yc"
 //发布到JCenter上的项目名字,必须填写
 def libName = "YCVideoKernelLib"
 // 版本号,下次更新是只需要更改版本号即可
-version = "1.0.0"
+version = "3.0.0"
 /**  上面配置后上传至jcenter后的编译路径是这样的: compile 'cn.yc:YCVideoKernelLib:1.0.0'  **/
 
 //生成源文件

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

@@ -68,6 +68,7 @@ public class ExoMediaPlayer extends AbstractVideoPlayer implements VideoListener
 
     @Override
     public void initPlayer() {
+        //创建exo播放器
         mInternalPlayer = new SimpleExoPlayer.Builder(
                 mAppContext,
                 mRenderersFactory == null ? mRenderersFactory = new DefaultRenderersFactory(mAppContext) : mRenderersFactory,
@@ -147,6 +148,7 @@ public class ExoMediaPlayer extends AbstractVideoPlayer implements VideoListener
         }
         mIsPreparing = true;
         mMediaSource.addEventListener(new Handler(), mMediaSourceEventListener);
+        //准备播放
         mInternalPlayer.prepare(mMediaSource);
     }
 

+ 17 - 1
VideoKernel/src/main/java/com/yc/kernel/utils/PlayerConstant.java

@@ -1,5 +1,8 @@
 package com.yc.kernel.utils;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
 /**
  * <pre>
  *     @author yangchong
@@ -37,5 +40,18 @@ public final class PlayerConstant {
      */
     public static final int MEDIA_INFO_VIDEO_ROTATION_CHANGED = 10001;
 
-
+    /**
+     * 通过注解限定类型
+     * TYPE_IJK                 IjkPlayer,基于IjkPlayer封装播放器
+     * TYPE_NATIVE              MediaPlayer,基于原生自带的播放器控件
+     * TYPE_EXO                 基于谷歌视频播放器
+     * TYPE_RTC                 基于RTC视频播放器
+     */
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface PlayerType {
+        int TYPE_IJK = 1;
+        int TYPE_NATIVE = 2;
+        int TYPE_EXO = 3;
+        int TYPE_RTC = 4;
+    }
 }

+ 42 - 0
VideoKernel/src/main/java/com/yc/kernel/utils/PlayerFactoryUtils.java

@@ -0,0 +1,42 @@
+package com.yc.kernel.utils;
+
+import com.yc.kernel.factory.PlayerFactory;
+import com.yc.kernel.impl.exo.ExoPlayerFactory;
+import com.yc.kernel.impl.ijk.IjkPlayerFactory;
+import com.yc.kernel.impl.media.MediaPlayerFactory;
+
+/**
+ * <pre>
+ *     @author yangchong
+ *     blog  : https://github.com/yangchong211
+ *     time  : 2017/10/21
+ *     desc  : 工具类
+ *     revise:
+ * </pre>
+ */
+public final class PlayerFactoryUtils {
+
+    /**
+     * 获取PlayerFactory具体实现类,获取内核
+     * TYPE_IJK                 IjkPlayer,基于IjkPlayer封装播放器
+     * TYPE_NATIVE              MediaPlayer,基于原生自带的播放器控件
+     * TYPE_EXO                 基于谷歌视频播放器
+     * TYPE_RTC                 基于RTC视频播放器
+     * @param type                              类型
+     * @return
+     */
+    public static PlayerFactory getPlayer(@PlayerConstant.PlayerType int type){
+        if (type == PlayerConstant.PlayerType.TYPE_EXO){
+            return ExoPlayerFactory.create();
+        } else if (type == PlayerConstant.PlayerType.TYPE_IJK){
+            return IjkPlayerFactory.create();
+        } else if (type == PlayerConstant.PlayerType.TYPE_NATIVE){
+            return MediaPlayerFactory.create();
+        } else if (type == PlayerConstant.PlayerType.TYPE_RTC){
+            return IjkPlayerFactory.create();
+        } else {
+            return IjkPlayerFactory.create();
+        }
+    }
+
+}

+ 7 - 9
VideoPlayer/build.gradle

@@ -6,8 +6,8 @@ android {
     defaultConfig {
         minSdkVersion 17
         targetSdkVersion 29
-        versionCode 18
-        versionName "2.6.4"
+        versionCode 30
+        versionName "3.0.0"
     }
 
     buildTypes {
@@ -23,10 +23,10 @@ dependencies {
     implementation 'androidx.appcompat:appcompat:1.2.0'
     implementation 'androidx.annotation:annotation:1.1.0'
     implementation 'androidx.cardview:cardview:1.0.0'
-
     implementation project(':VideoKernel')
 
-    //这两个是必须要加的,其它的可供选择
+    /*//这两个是必须要加的,其它的可供选择
+    //ijk播放器
     implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
     implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4'
     //其他库文件
@@ -34,15 +34,13 @@ dependencies {
     //implementation 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8'
     //implementation 'tv.danmaku.ijk.media:ijkplayer-x86:0.8.8'
     //implementation 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.8.8'
-
-
     //谷歌播放器
     implementation  "com.google.android.exoplayer:exoplayer:2.11.3"
     implementation "com.google.android.exoplayer:exoplayer-core:2.11.3"
     implementation "com.google.android.exoplayer:exoplayer-dash:2.11.3"
     implementation "com.google.android.exoplayer:exoplayer-hls:2.11.3"
     implementation "com.google.android.exoplayer:exoplayer-smoothstreaming:2.11.3"
-    implementation "com.google.android.exoplayer:extension-rtmp:2.11.3"
+    implementation "com.google.android.exoplayer:extension-rtmp:2.11.3"*/
 }
 
 /** 以下开始是将Android Library上传到jcenter的相关配置**/
@@ -57,9 +55,9 @@ def gitUrl = 'https://github.com/yangchong211/YCVideoPlayer.git' // project git
 //发布到组织名称名字,必须填写
 group = "cn.yc"
 //发布到JCenter上的项目名字,必须填写
-def libName = "YCVideoPlayerLib"
+def libName = "VideoPlayer"
 // 版本号,下次更新是只需要更改版本号即可
-version = "2.6.6"
+version = "3.0.1"
 /**  上面配置后上传至jcenter后的编译路径是这样的: compile 'cn.yc:YCVideoPlayerLib:2.4'  **/
 
 //生成源文件

+ 9 - 2
read/03.视频播放器Api说明.md

@@ -287,8 +287,15 @@
     //设置是否锁屏
     controller.setLocked(true);
     ```
-- 设置播放视频缩放类型
-
+- 设置播放视频缩放类型。借鉴于网络博客,类似图片缩放。建议选择16:9类型,最常见
+    ```
+    mVideoPlayer.setScreenScaleType(ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_16_9);
+    mVideoPlayer.setScreenScaleType(ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_DEFAULT);
+    mVideoPlayer.setScreenScaleType(ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_4_3);
+    mVideoPlayer.setScreenScaleType(ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_MATCH_PARENT);
+    mVideoPlayer.setScreenScaleType(ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_ORIGINAL);
+    mVideoPlayer.setScreenScaleType(ConstantKeys.PlayerScreenScaleType.SCREEN_SCALE_CENTER_CROP);
+    ```
 
 
 

+ 14 - 1
read/08.视频播放器优化处理.md

@@ -13,7 +13,7 @@
 - 11.SurfaceView和TextureView
 - 12.视频旋转角度float数值对比优化
 - 13.如何做到一次播放一个视频
-
+- 16.关于依赖优化
 
 
 ### 02.前后台切换优化
@@ -270,6 +270,19 @@
     ```
 
 
+### 16.关于依赖优化
+- implementation:
+    - 只能在内部使用此模块,比如我在一个libiary中使用implementation依赖了gson库,然后我的主项目依赖了libiary,那么,我的主项目就无法访问gson库中的方法。这样的好处是编译速度会加快,推荐使用implementation的方式去依赖
+- compile(api)
+    - 这种是我们最常用的方式,使用该方式依赖的库将会参与编译和打包。 
+- compileOnly
+    - 使用场景:有多个library,只要确保有一个module中该依赖能参与到打包即可,其他的可以使用compileOnly。运行时不需要,例如仅源代码注解或注释处理器
+
+
+
+
+
+