Pārlūkot izejas kodu

解决播放器加载视频显示Unable to connect to url的问题

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

+ 4 - 4
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/kernel/controller/BaseVideoController.java

@@ -18,7 +18,7 @@ import androidx.annotation.Nullable;
 
 import org.yczbj.ycvideoplayerlib.kernel.player.VideoViewManager;
 import org.yczbj.ycvideoplayerlib.kernel.view.VideoView;
-import org.yczbj.ycvideoplayerlib.tool.utils.CutoutUtil;
+import org.yczbj.ycvideoplayerlib.tool.utils.CutoutUtils;
 import org.yczbj.ycvideoplayerlib.tool.utils.NetworkUtils;
 import org.yczbj.ycvideoplayerlib.tool.utils.PlayerUtils;
 import org.yczbj.ycvideoplayerlib.tool.utils.VideoLogUtils;
@@ -330,7 +330,7 @@ public abstract class BaseVideoController extends FrameLayout implements IVideoC
     private void checkCutout() {
         if (!mAdaptCutout) return;
         if (mActivity != null && mHasCutout == null) {
-            mHasCutout = CutoutUtil.allowDisplayToCutout(mActivity);
+            mHasCutout = CutoutUtils.allowDisplayToCutout(mActivity);
             if (mHasCutout) {
                 //竖屏下的状态栏高度可认为是刘海的高度
                 mCutoutHeight = (int) PlayerUtils.getStatusBarHeightPortrait(mActivity);
@@ -595,14 +595,14 @@ public abstract class BaseVideoController extends FrameLayout implements IVideoC
                     mOrientationHelper.disable();
                 }
                 if (hasCutout()) {
-                    CutoutUtil.adaptCutoutAboveAndroidP(getContext(), false);
+                    CutoutUtils.adaptCutoutAboveAndroidP(getContext(), false);
                 }
                 break;
             case VideoView.PLAYER_FULL_SCREEN:
                 //在全屏时强制监听设备方向
                 mOrientationHelper.enable();
                 if (hasCutout()) {
-                    CutoutUtil.adaptCutoutAboveAndroidP(getContext(), true);
+                    CutoutUtils.adaptCutoutAboveAndroidP(getContext(), true);
                 }
                 break;
             case VideoView.PLAYER_TINY_SCREEN:

+ 3 - 1
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/kernel/player/VideoViewManager.java

@@ -132,7 +132,9 @@ public class VideoViewManager {
 
     public boolean onBackPress(String tag) {
         VideoView videoView = get(tag);
-        if (videoView == null) return false;
+        if (videoView == null) {
+            return false;
+        }
         return videoView.onBackPressed();
     }
 

+ 19 - 0
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/tool/timer/CountDownTimer.java

@@ -193,4 +193,23 @@ public class CountDownTimer {
         this.mCountDownListener = countDownListener;
     }
 
+    public interface TimerListener {
+
+        /**
+         * 当倒计时开始
+         */
+        void onStart();
+
+        /**
+         * 当倒计时结束
+         */
+        void onFinish();
+
+        /**
+         * @param millisUntilFinished 剩余时间
+         */
+        void onTick(long millisUntilFinished);
+
+    }
+
 }

+ 0 - 101
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/tool/timer/CountTimeTools.java

@@ -1,101 +0,0 @@
-package org.yczbj.ycvideoplayerlib.tool.timer;
-
-/**
- * <pre>
- *     @author  yangchong
- *     email  : yangchong211@163.com
- *     time  :  2020/5/26
- *     desc  :  工具类
- *     revise:
- * </pre>
- */
-public final class CountTimeTools {
-
-    /**
-     * 将毫秒换成00:00:00
-     * @param time                          毫秒
-     * @return                              时间字符串
-     */
-    public static String getCountTimeByLong(long time) {
-        //秒
-        long totalTime = time / 1000;
-        //时,分,秒
-        long hour = 0, minute = 0, second = 0;
-
-        if (3600 <= totalTime) {
-            hour = totalTime / 3600;
-            totalTime = totalTime - 3600 * hour;
-        }
-        if (60 <= totalTime) {
-            minute = totalTime / 60;
-            totalTime = totalTime - 60 * minute;
-        }
-        if (0 <= totalTime) {
-            second = totalTime;
-        }
-        StringBuilder sb = new StringBuilder();
-        if (hour < 10) {
-            sb.append("0").append(hour).append(":");
-        } else {
-            sb.append(hour).append(":");
-        }
-        if (minute < 10) {
-            sb.append("0").append(minute).append(":");
-        } else {
-            sb.append(minute).append(":");
-        }
-        if (second < 10) {
-            sb.append("0").append(second);
-        } else {
-            sb.append(second);
-        }
-        return sb.toString();
-    }
-
-
-    /**
-     * 将毫秒换成 00:00 或者 00,这个根据具体时间来计算
-     * @param time                          毫秒
-     * @return                              时间字符串
-     */
-    public static String getCountTime(long time) {
-        //秒
-        long totalTime = time / 1000;
-        //时,分,秒
-        long hour = 0, minute = 0, second = 0;
-
-        if (3600 <= totalTime) {
-            hour = totalTime / 3600;
-            totalTime = totalTime - 3600 * hour;
-        }
-        if (60 <= totalTime) {
-            minute = totalTime / 60;
-            totalTime = totalTime - 60 * minute;
-        }
-        if (0 <= totalTime) {
-            second = totalTime;
-        }
-        StringBuilder sb = new StringBuilder();
-        if (hour>0){
-            if (hour < 10) {
-                sb.append("0").append(hour).append(":");
-            } else {
-                sb.append(hour).append(":");
-            }
-        }
-        if (minute>0){
-            if (minute < 10) {
-                sb.append("0").append(minute).append(":");
-            } else {
-                sb.append(minute).append(":");
-            }
-        }
-        if (second < 10) {
-            sb.append("0").append(second);
-        } else {
-            sb.append(second);
-        }
-        return sb.toString();
-    }
-
-}

+ 0 - 29
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/tool/timer/TimerListener.java

@@ -1,29 +0,0 @@
-package org.yczbj.ycvideoplayerlib.tool.timer;
-
-/**
- * <pre>
- *     @author  yangchong
- *     email  : yangchong211@163.com
- *     time  :  2020/5/26
- *     desc  :  倒计时监听器
- *     revise:
- * </pre>
- */
-public interface TimerListener {
-
-    /**
-     * 当倒计时开始
-     */
-    void onStart();
-
-    /**
-     * 当倒计时结束
-     */
-    void onFinish();
-
-    /**
-     * @param millisUntilFinished 剩余时间
-     */
-    void onTick(long millisUntilFinished);
-
-}

+ 3 - 2
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/tool/utils/CutoutUtil.java → VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/tool/utils/CutoutUtils.java

@@ -16,9 +16,10 @@ import java.util.List;
 /**
  * 刘海屏工具
  */
-public final class CutoutUtil {
+public final class CutoutUtils {
+
+    private CutoutUtils() {
 
-    private CutoutUtil() {
     }
 
     /**

+ 88 - 0
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/tool/utils/PlayerUtils.java

@@ -406,4 +406,92 @@ public final class PlayerUtils {
     }
 
 
+    /**
+     * 将毫秒换成00:00:00
+     * @param time                          毫秒
+     * @return                              时间字符串
+     */
+    public static String getCountTimeByLong(long time) {
+        //秒
+        long totalTime = time / 1000;
+        //时,分,秒
+        long hour = 0, minute = 0, second = 0;
+
+        if (3600 <= totalTime) {
+            hour = totalTime / 3600;
+            totalTime = totalTime - 3600 * hour;
+        }
+        if (60 <= totalTime) {
+            minute = totalTime / 60;
+            totalTime = totalTime - 60 * minute;
+        }
+        if (0 <= totalTime) {
+            second = totalTime;
+        }
+        StringBuilder sb = new StringBuilder();
+        if (hour < 10) {
+            sb.append("0").append(hour).append(":");
+        } else {
+            sb.append(hour).append(":");
+        }
+        if (minute < 10) {
+            sb.append("0").append(minute).append(":");
+        } else {
+            sb.append(minute).append(":");
+        }
+        if (second < 10) {
+            sb.append("0").append(second);
+        } else {
+            sb.append(second);
+        }
+        return sb.toString();
+    }
+
+
+    /**
+     * 将毫秒换成 00:00 或者 00,这个根据具体时间来计算
+     * @param time                          毫秒
+     * @return                              时间字符串
+     */
+    public static String getCountTime(long time) {
+        //秒
+        long totalTime = time / 1000;
+        //时,分,秒
+        long hour = 0, minute = 0, second = 0;
+
+        if (3600 <= totalTime) {
+            hour = totalTime / 3600;
+            totalTime = totalTime - 3600 * hour;
+        }
+        if (60 <= totalTime) {
+            minute = totalTime / 60;
+            totalTime = totalTime - 60 * minute;
+        }
+        if (0 <= totalTime) {
+            second = totalTime;
+        }
+        StringBuilder sb = new StringBuilder();
+        if (hour>0){
+            if (hour < 10) {
+                sb.append("0").append(hour).append(":");
+            } else {
+                sb.append(hour).append(":");
+            }
+        }
+        if (minute>0){
+            if (minute < 10) {
+                sb.append("0").append(minute).append(":");
+            } else {
+                sb.append(minute).append(":");
+            }
+        }
+        if (second < 10) {
+            sb.append("0").append(second);
+        } else {
+            sb.append(second);
+        }
+        return sb.toString();
+    }
+
+
 }

+ 1 - 0
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/tool/utils/Utils.java

@@ -13,6 +13,7 @@ import java.lang.reflect.Field;
 public final class Utils {
 
     private Utils() {
+
     }
 
 

+ 0 - 144
VideoPlayer/src/main/java/org/yczbj/ycvideoplayerlib/view/states/StatesPlayerController.java

@@ -1,144 +0,0 @@
-package org.yczbj.ycvideoplayerlib.view.states;
-
-import android.content.Context;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.RelativeLayout;
-import org.yczbj.ycvideoplayerlib.ui.CustomGuideView;
-
-/**
- * <pre>
- *     @author yangchong
- *     blog  : https://github.com/yangchong211
- *     time  : 2019/10/21
- *     desc  : 状态操作层,负责各个视图view的状态切换
- *     revise:
- * </pre>
- */
-public class StatesPlayerController extends RelativeLayout {
-
-    private Context context;
-    private CustomGuideView mGuideView;
-
-    public StatesPlayerController(@NonNull Context context) {
-        super(context);
-        initView(context);
-    }
-
-    public StatesPlayerController(@NonNull Context context, @Nullable AttributeSet attrs) {
-        super(context, attrs);
-        initView(context);
-    }
-
-    public StatesPlayerController(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
-        super(context, attrs, defStyleAttr);
-        initView(context);
-    }
-
-    private void initView(Context context) {
-        this.context = context;
-        //初始化播放用的surfaceView
-        //initSurfaceView();
-        //初始化控制栏
-        //initBasisControlView();
-        //初始化引导图视图
-        //initGuideView();
-        //初始化播放器
-        //initVideoPlayer();
-        //初始化封面
-        //initCoverView();
-        //初始化手势view
-        //initGestureView();
-        //初始化清晰度view
-        //initQualityView();
-        //初始化缩略图
-        //initThumbnailView();
-        //初始化倍速view
-        //initSpeedView();
-        //初始化指引view
-        initGuideView();
-        //初始化提示view
-        //initTipsView();
-        //初始化网络监听器
-        //initNetWatchdog();
-        //初始化屏幕方向监听
-        //initOrientationWatchdog();
-        //初始化手势对话框控制
-        //initGestureDialogManager();
-
-        //直播
-        boolean isZhiBo = true;
-        if (isZhiBo){
-            //初始化指引view
-            //initGuideView();
-            //初始化提示view
-            //initTipsView();
-            //初始化网络监听器
-            //initNetWatchdog();
-        }
-
-        //投屏
-        boolean isScreen = true;
-        if (isScreen){
-            //初始化指引view
-            //initGuideView();
-            //初始化提示view
-            //initTipsView();
-            //初始化网络监听器
-            //initNetWatchdog();
-        }
-    }
-
-    /**
-     * addSubView 添加子view到布局中
-     * @param view                          子view
-     */
-    private void addSubView(View view) {
-        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
-        //添加到布局中
-        addView(view, params);
-    }
-
-    /**
-     * 添加子View到布局中央
-     * @param view                          子view
-     */
-    private void addSubViewByCenter(View view) {
-        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
-        params.addRule(RelativeLayout.CENTER_IN_PARENT);
-        addView(view, params);
-    }
-
-    /**
-     * 添加子View到布局中,在某个View的下方
-     * @param view                          需要添加的View
-     * @param belowTargetView               在这个View的下方
-     */
-    private void addSubViewBelow(final View view, final View belowTargetView) {
-        belowTargetView.post(new Runnable() {
-            @Override
-            public void run() {
-                LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
-                int measuredHeight = belowTargetView.getMeasuredHeight();
-                params.topMargin = measuredHeight;
-                //添加到布局中
-                addView(view, params);
-            }
-        });
-    }
-
-    /**
-     * 初始化引导view
-     */
-    private void initGuideView() {
-        mGuideView = new CustomGuideView(getContext());
-        addSubView(mGuideView);
-        //切换状态的操作逻辑,调用api即可
-        mGuideView.hide();
-        mGuideView.setScreenMode(1);
-    }
-
-
-}

+ 1 - 35
app/src/main/AndroidManifest.xml

@@ -15,6 +15,7 @@
         android:label="@string/app_name"
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
+        android:networkSecurityConfig="@xml/network_security_config"
         android:theme="@style/AppTheme"
         tools:ignore="GoogleAppIndexingWarning">
         <activity android:name=".MainActivity"
@@ -28,41 +29,6 @@
         </activity>
 
 
-        <!--用于AppLink,html跳到此页面  scheme_Adr: 'yilu://link/?page=main',-->
-        <activity android:name=".SchemeActivity"
-            android:screenOrientation="portrait">
-            <!--Android 接收外部跳转过滤器-->
-            <intent-filter android:autoVerify="true">
-                <action android:name="android.intent.action.VIEW" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.BROWSABLE" />
-                <data android:scheme="http"/>
-                <data android:scheme="https"/>
-                <data android:host="yc.com"/>
-            </intent-filter>
-            <intent-filter >
-                <action android:name="android.intent.action.VIEW" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.BROWSABLE" />
-                <!-- 协议部分配置 ,要在web配置相同的-->
-                <!--yilu://link/?page=main-->
-                <data
-                    android:host="link"
-                    android:scheme="yilu" />
-            </intent-filter>
-
-            <intent-filter >
-                <action android:name="android.intent.action.VIEW" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.BROWSABLE" />
-                <!-- 协议部分配置 ,要在web配置相同的-->
-                <!--yilu://www.yc.com/?page=main-->
-                <data
-                    android:host="www.yc.com"
-                    android:scheme="yilu" />
-            </intent-filter>
-        </activity>
-
         <activity android:name=".TestTinyActivity"
             android:configChanges="orientation|keyboardHidden|screenSize"
             android:screenOrientation="portrait"/>

+ 18 - 0
app/src/main/java/org/yczbj/ycvideoplayer/BaseApplication.java

@@ -6,6 +6,9 @@ import android.content.res.Configuration;
 import android.util.Log;
 
 
+import org.yczbj.ycvideoplayerlib.kernel.impl.ijk.IjkPlayerFactory;
+import org.yczbj.ycvideoplayerlib.kernel.player.VideoViewConfig;
+import org.yczbj.ycvideoplayerlib.kernel.player.VideoViewManager;
 import org.yczbj.ycvideoplayerlib.tool.utils.VideoLogUtils;
 
 /**
@@ -55,6 +58,21 @@ public class BaseApplication extends Application {
         }else {
             VideoLogUtils.setIsLog(false);
         }
+
+
+        //播放器配置,注意:此为全局配置,按需开启
+        VideoViewManager.setConfig(VideoViewConfig.newBuilder()
+                .setLogEnabled(BuildConfig.DEBUG)//调试的时候请打开日志,方便排错
+                .setPlayerFactory(IjkPlayerFactory.create())
+//                .setPlayerFactory(ExoMediaPlayerFactory.create())
+//                .setRenderViewFactory(SurfaceRenderViewFactory.create())
+//                .setEnableOrientation(true)
+//                .setEnableAudioFocus(false)
+//                .setScreenScaleType(VideoView.SCREEN_SCALE_MATCH_PARENT)
+//                .setAdaptCutout(false)
+//                .setPlayOnMobileNetwork(true)
+//                .setProgressManager(new ProgressManagerImpl())
+                .build());
     }
 
     /**

+ 0 - 201
app/src/main/java/org/yczbj/ycvideoplayer/SchemeActivity.java

@@ -1,201 +0,0 @@
-package org.yczbj.ycvideoplayer;
-
-import android.app.ActivityManager;
-import android.content.Context;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.AppCompatActivity;
-
-import org.yczbj.ycvideoplayer.list.TestListActivity;
-import org.yczbj.ycvideoplayer.tiny.TestFullActivity;
-import org.yczbj.ycvideoplayerlib.tool.utils.VideoLogUtils;
-
-import java.util.List;
-
-
-/**
- * <pre>
- *     @author yangchong
- *     blog  : https://github.com/yangchong211
- *     time  : 2019/11/29
- *     desc  : scheme协议页面
- *     revise: AppLink
- * </pre>
- */
-public class SchemeActivity extends AppCompatActivity {
-
-    /**
-     * URL Scheme使用场景,目前1,2,5使用场景很广
-     * 1.通过小程序,利用Scheme协议打开原生app
-     * 2.H5页面点击锚点,根据锚点具体跳转路径APP端跳转具体的页面
-     * 3.APP端收到服务器端下发的PUSH通知栏消息,根据消息的点击跳转路径跳转相关页面
-     * 4.APP根据URL跳转到另外一个APP指定页面
-     * 5.通过短信息中的url打开原生app
-     */
-
-    @Override
-    protected void onCreate(@Nullable Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        try {
-            getDataFromBrower();
-        } catch (Exception e){
-            e.printStackTrace();
-            Intent intent = new Intent(this, MainActivity.class);
-            readGoActivity(intent, this);
-        }
-        finish();
-    }
-
-    private void getDataFromBrower() {
-        Uri uri = getIntent().getData();
-        if (uri != null) {
-            // 完整的url信息
-            String url = uri.toString();
-            VideoLogUtils.i("SchemeActivity---" + "url: " + uri);
-            // scheme部分
-            String scheme = uri.getScheme();
-            VideoLogUtils.i("SchemeActivity---" + "scheme: " + scheme);
-            // host部分
-            String host = uri.getHost();
-            VideoLogUtils.i("SchemeActivity---" + "host: " + host);
-            //port部分
-            int port = uri.getPort();
-            VideoLogUtils.i("SchemeActivity---" + "host: " + port);
-            // 访问路劲
-            String path = uri.getPath();
-            VideoLogUtils.i("SchemeActivity---" + "path: " + path);
-            // 获取参数
-            List<String> pathSegments = uri.getPathSegments();
-            VideoLogUtils.i("SchemeActivity---" + "pathSegments: " + pathSegments.size());
-            // Query部分
-            String query = uri.getQuery();
-            VideoLogUtils.i("SchemeActivity---" + "query: " + query);
-            //获取指定参数值
-            String page = uri.getQueryParameter("page");
-            VideoLogUtils.i("SchemeActivity---" + "page: " + page);
-
-            //获取指定参数值,该方法获取值一直是空
-            //String level = uri.getQueryParameter("level");
-            ///Log.e( "UrlUtils","level: " + level);
-
-            //String level = getValueByName(url, "level");
-            //LoggerUtils.i( "SchemeActivity---","level: " + level);
-            if (page==null || page.length()==0) {
-                finish();
-                return;
-            }
-            switch (page) {
-                case "main":
-                    //唤起客户端,进入首页
-                    //https://yc.com?page=main
-                    Intent intent1 = new Intent(this, MainActivity.class);
-                    readGoActivity(intent1, this);
-                    break;
-                case "full":
-                    //唤起客户端,进入A页面
-                    //https://yc.com?page=full
-                    Intent intent2 = new Intent(this, TestFullActivity.class);
-                    readGoActivity(intent2, this);
-                    break;
-                case "list":
-                    //唤起客户端,进入B页面,携带参数
-                    //https://yc.com?page=list&id=520
-                    Intent intent3 = new Intent(this, TestListActivity.class);
-                    String id = getValueByName(url, "id");
-                    intent3.putExtra("id",id);
-                    readGoActivity(intent3, this);
-                    break;
-                case "small":
-                    //唤起客户端,进入C页面
-                    Intent intent4 = new Intent(this, TestRecyclerActivity.class);
-                    readGoActivity(intent4, this);
-                    break;
-                default:
-                    Intent intent = new Intent(this, MainActivity.class);
-                    readGoActivity(intent, this);
-                    break;
-            }
-        }
-    }
-
-
-    /***
-     * 获取url 指定name的value;
-     * @param url                       url
-     * @param name                      参数名
-     * @return 获取某个参数值
-     */
-    private String getValueByName(String url, String name) {
-        String result = "";
-        //如果不包含参数就直接返回,避免空指针异常
-        if (!url.contains("?")) {
-            return result;
-        }
-        int index = url.indexOf("?");
-        String temp = url.substring(index + 1);
-        if (temp.contains("&")) {
-            String[] keyValue = temp.split("&");
-            for (String str : keyValue) {
-                if (str.contains(name)) {
-                    result = str.replace(name + "=", "");
-                    break;
-                }
-            }
-        }
-        return result;
-    }
-
-    public void readGoActivity(Intent intent, Context context) {
-        // 如果app 运行中,直接打开页面,没有运行中就先打开主界面,在打开
-        if (isAppRunning(context, context.getPackageName())) {
-            openActivity(intent, context);
-        } else {
-            //先打开首页,然后跳转指定页面
-            reStartActivity(intent, context);
-        }
-    }
-
-    public void openActivity(Intent intent, Context context) {
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        context.startActivity(intent);
-    }
-
-    /**
-     * 注意,为何要这样跳转,首先需要先跳转首页,然后在跳转到指定页面,那么回来的时候始终是首页Main页面
-     * @param intent                            intent
-     * @param context                           上下文
-     */
-    public void reStartActivity(Intent intent, Context context) {
-        Intent[] intents = new Intent[2];
-        Intent mainIntent = new Intent(context, MainActivity.class);
-        mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        intents[0] = mainIntent;
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        intents[1] = intent;
-        context.startActivities(intents);
-    }
-
-    /**
-     * 判断app是否正在运行
-     * @param context                           上下文
-     * @param packageName                       应用的包名
-     * @return true 表示正在运行,false 表示没有运行
-     */
-    public boolean isAppRunning(Context context, String packageName) {
-        ActivityManager am = (ActivityManager) context.getApplicationContext()
-                .getSystemService(Context.ACTIVITY_SERVICE);
-        List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(100);
-        if (list.size() <= 0) {
-            return false;
-        }
-        for (ActivityManager.RunningTaskInfo info : list) {
-            if (info.baseActivity.getPackageName().equals(packageName)) {
-                return true;
-            }
-        }
-        return false;
-    }
-}

+ 15 - 1
app/src/main/java/org/yczbj/ycvideoplayer/activity/TypeActivity.java

@@ -27,6 +27,7 @@ import org.yczbj.ycvideoplayerlib.kernel.player.PlayerFactory;
 import org.yczbj.ycvideoplayerlib.kernel.player.VideoViewConfig;
 import org.yczbj.ycvideoplayerlib.kernel.player.VideoViewManager;
 import org.yczbj.ycvideoplayerlib.tool.toast.BaseToast;
+import org.yczbj.ycvideoplayerlib.tool.utils.Utils;
 
 import java.lang.reflect.Field;
 
@@ -54,13 +55,26 @@ public class TypeActivity extends AppCompatActivity implements View.OnClickListe
     private TextView mTv111;
     private TextView mTv131;
 
+    @SuppressLint("SetTextI18n")
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         initFindViewById();
         initListener();
-        setChangeVideoType(ConstantKeys.VideoPlayerType.TYPE_IJK);
+
+        //检测当前是用的哪个播放器
+        Object factory = Utils.getCurrentPlayerFactory();
+        if (factory instanceof ExoMediaPlayerFactory) {
+            mTvTitle.setText("视频内核:" + " (ExoPlayer)");
+            setTitle(getResources().getString(R.string.app_name) + " (ExoPlayer)");
+        } else if (factory instanceof IjkPlayerFactory) {
+            mTvTitle.setText("视频内核:" + " (IjkPlayer)");
+        } else if (factory instanceof AndroidMediaPlayerFactory) {
+            mTvTitle.setText("视频内核:" + " (MediaPlayer)");
+        } else {
+            mTvTitle.setText("视频内核:" + " (unknown)");
+        }
     }
 
     private void initFindViewById() {

+ 4 - 0
app/src/main/res/xml/network_security_config.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<network-security-config>
+    <base-config cleartextTrafficPermitted="true"/>
+</network-security-config>

+ 0 - 0
read/api.md → read/03.视频播放器Api说明.md


+ 33 - 0
read/17.基础播放器问题记录.md

@@ -0,0 +1,33 @@
+# 基础方法说明
+#### 目录介绍
+- 14.播放器加载视频显示Unable to connect to url
+
+
+
+### 14.播放器加载视频显示Unable to connect to url
+- 详细报错日志如下所示
+    ``` java
+    com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to http://vfx.mtime.cn/Video/2019/02/04/mp4/190204084208765161.mp4
+    Caused by: java.io.IOException: Cleartext HTTP traffic to vfx.mtime.cn not permitted
+    ```
+- 如何解决这个问题
+    - Android9.0 默认是禁止所有的http。所以不能访问,才会出现这个错误。
+    - 请求的,需要在代码中设置如下代码才可以正常进行网络请求: android:usesCleartextTraffic="true"。最好是添加配置文件,代码如下所示:
+    ```
+    <?xml version="1.0" encoding="utf-8"?>
+    <network-security-config>
+        <base-config cleartextTrafficPermitted="true"/>
+    </network-security-config>
+    ```
+    - 之后在application中添加配置如下,即可:
+    ```
+    <application
+           .....
+            android:networkSecurityConfig="@xml/network_security_config"
+            .......>
+    ```
+
+
+
+
+

+ 9 - 0
read/18.Exo播放器问题记录.md

@@ -0,0 +1,9 @@
+# 基础方法说明
+#### 目录介绍
+- 14.exo加载视频显示Unable to connect to url
+
+
+
+
+
+

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

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

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

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