杨充 пре 4 година
родитељ
комит
5b3b217757

+ 3 - 6
.idea/modules.xml

@@ -3,13 +3,10 @@
   <component name="ProjectModuleManager">
     <modules>
       <module fileurl="file://$PROJECT_DIR$/Demo/Demo.iml" filepath="$PROJECT_DIR$/Demo/Demo.iml" group="YCVideoPlayer/Demo" />
-      <module fileurl="file://$PROJECT_DIR$/GitHub-YCVideoPlayer.iml" filepath="$PROJECT_DIR$/GitHub-YCVideoPlayer.iml" group="YCVideoPlayer" />
-      <module fileurl="file://$PROJECT_DIR$/.idea/modules/VideoCache/VideoCache.iml" filepath="$PROJECT_DIR$/.idea/modules/VideoCache/VideoCache.iml" group="YCVideoPlayer/VideoCache" />
-      <module fileurl="file://$PROJECT_DIR$/.idea/modules/VideoBarrage/VideoKernel.iml" filepath="$PROJECT_DIR$/.idea/modules/VideoBarrage/VideoKernel.iml" group="YCVideoPlayer/VideoKernel" />
+      <module fileurl="file://$PROJECT_DIR$/VideoCache/VideoCache.iml" filepath="$PROJECT_DIR$/VideoCache/VideoCache.iml" group="YCVideoPlayer/VideoCache" />
+      <module fileurl="file://$PROJECT_DIR$/VideoKernel/VideoKernel.iml" filepath="$PROJECT_DIR$/VideoKernel/VideoKernel.iml" group="YCVideoPlayer/VideoKernel" />
       <module fileurl="file://$PROJECT_DIR$/VideoPlayer/VideoPlayer.iml" filepath="$PROJECT_DIR$/VideoPlayer/VideoPlayer.iml" group="YCVideoPlayer/VideoPlayer" />
-      <module fileurl="file://$PROJECT_DIR$/.idea/YCVideoPlayer.iml" filepath="$PROJECT_DIR$/.idea/YCVideoPlayer.iml" />
-      <module fileurl="file://$PROJECT_DIR$/VideoPlayer/YCVideoPlayerLib.iml" filepath="$PROJECT_DIR$/VideoPlayer/YCVideoPlayerLib.iml" />
-      <module fileurl="file://$PROJECT_DIR$/Demo/app.iml" filepath="$PROJECT_DIR$/Demo/app.iml" />
+      <module fileurl="file://$PROJECT_DIR$/YCVideoPlayer.iml" filepath="$PROJECT_DIR$/YCVideoPlayer.iml" group="YCVideoPlayer" />
     </modules>
   </component>
 </project>

BIN
image/视频播放器内核架构图.jpg


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

@@ -213,13 +213,20 @@
 #### 6.3 视频播放器lib库
 ![image](https://img-blog.csdnimg.cn/20201013092150588.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3NzAwMjc1,size_16,color_FFFFFF,t_70#pic_center)
 
+
+
 #### 6.4 视频内核lib库介绍
 ![image](https://img-blog.csdnimg.cn/2020101309293329.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3NzAwMjc1,size_16,color_FFFFFF,t_70#pic_center)
+![image](https://img-blog.csdnimg.cn/2020101321464162.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3NzAwMjc1,size_16,color_FFFFFF,t_70#pic_center)
+
 
 #### 6.5视频播放器UI库介绍
 ![image](https://img-blog.csdnimg.cn/20201013094115174.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3NzAwMjc1,size_16,color_FFFFFF,t_70#pic_center)
 
 
+
+
+
 ### 07.播放器示例展示图
 ![image](https://img-blog.csdnimg.cn/20201013091432693.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3NzAwMjc1,size_16,color_FFFFFF,t_70#pic_center)
 ![image](https://img-blog.csdnimg.cn/20201013091432695.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3NzAwMjc1,size_16,color_FFFFFF,t_70#pic_center)

+ 83 - 11
read/05.播放器内核切换封装.md

@@ -1,15 +1,87 @@
-# 视频封装思路
+# 05.视频封装思路
 #### 目录介绍
-
-
-
-
-
-
-
-
-
-
+- 01.视频播放器内核封装需求
+- 02.播放器内核架构图
+- 06.介绍一下简单工厂模式
+
+
+
+### 01.视频播放器内核封装需求
+
+
+### 02.播放器内核架构图
+![image](https://img-blog.csdnimg.cn/2020101321464162.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3NzAwMjc1,size_16,color_FFFFFF,t_70#pic_center)
+
+
+
+### 06.介绍一下简单工厂模式
+- 首先,我们来看,什么是简单工厂模式。
+    - 通过一个例子来解释一下。在下面这段代码中,我们根据配置文件的后缀(json、xml、yaml、properties),选择不同的解析器(JsonRuleConfigParser、XmlRuleConfigParser……),将存储在文件中的配置解析成内存对象 RuleConfig。
+    ```java
+    public class RuleConfigSource {
+      public RuleConfig load(String ruleConfigFilePath) {
+        String ruleConfigFileExtension = getFileExtension(ruleConfigFilePath);
+        IRuleConfigParser parser = null;
+        if ("json".equalsIgnoreCase(ruleConfigFileExtension)) {
+          parser = new JsonRuleConfigParser();
+        } else if ("xml".equalsIgnoreCase(ruleConfigFileExtension)) {
+          parser = new XmlRuleConfigParser();
+        } else if ("yaml".equalsIgnoreCase(ruleConfigFileExtension)) {
+          parser = new YamlRuleConfigParser();
+        } else if ("properties".equalsIgnoreCase(ruleConfigFileExtension)) {
+          parser = new PropertiesRuleConfigParser();
+        } else {
+          throw new InvalidRuleConfigException(
+                 "Rule config file format is not supported: " + ruleConfigFilePath);
+        }
+    
+        String configText = "";
+        //从ruleConfigFilePath文件中读取配置文本到configText中
+        RuleConfig ruleConfig = parser.parse(configText);
+        return ruleConfig;
+      }
+    
+      private String getFileExtension(String filePath) {
+        //...解析文件名获取扩展名,比如rule.json,返回json
+        return "json";
+      }
+    }
+    ```
+- 为了让代码逻辑更加清晰,可读性更好,要善于将功能独立的代码块封装成函数。按照这个设计思路,我们可以将代码中涉及 parser 创建的部分逻辑剥离出来,抽象成 createParser() 函数。重构之后的代码如下所示:
+    - 如果我们非得要将 if 分支逻辑去掉,那该怎么办呢?比较经典处理方法就是利用多态。按照多态的实现思路,对上面的代码进行重构。重构之后的代码如下所示:
+    ```java
+    public interface IRuleConfigParserFactory {
+      IRuleConfigParser createParser();
+    }
+    
+    public class JsonRuleConfigParserFactory implements IRuleConfigParserFactory {
+      @Override
+      public IRuleConfigParser createParser() {
+        return new JsonRuleConfigParser();
+      }
+    }
+    
+    public class XmlRuleConfigParserFactory implements IRuleConfigParserFactory {
+      @Override
+      public IRuleConfigParser createParser() {
+        return new XmlRuleConfigParser();
+      }
+    }
+    
+    public class YamlRuleConfigParserFactory implements IRuleConfigParserFactory {
+      @Override
+      public IRuleConfigParser createParser() {
+        return new YamlRuleConfigParser();
+      }
+    }
+    
+    public class PropertiesRuleConfigParserFactory implements IRuleConfigParserFactory {
+      @Override
+      public IRuleConfigParser createParser() {
+        return new PropertiesRuleConfigParser();
+      }
+    }
+    ```