1
0

BaseApplication.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package org.yczbj.ycvideoplayer;
  2. import android.app.Application;
  3. import android.content.Context;
  4. import android.content.res.Configuration;
  5. import android.util.Log;
  6. import com.yc.kernel.impl.ijk.IjkPlayerFactory;
  7. import com.yc.kernel.utils.VideoLogUtils;
  8. import org.yczbj.ycvideoplayerlib.player.VideoPlayerConfig;
  9. import org.yczbj.ycvideoplayerlib.player.VideoViewManager;
  10. /**
  11. * ================================================
  12. * 作 者:杨充
  13. * 版 本:1.0
  14. * 创建日期:2017/8/18
  15. * 描 述:BaseApplication
  16. * 修订历史:
  17. * ================================================
  18. */
  19. public class BaseApplication extends Application {
  20. private static BaseApplication instance;
  21. public static synchronized BaseApplication getInstance() {
  22. if (null == instance) {
  23. instance = new BaseApplication();
  24. }
  25. return instance;
  26. }
  27. public BaseApplication(){}
  28. /**
  29. * 这个最先执行
  30. */
  31. @Override
  32. protected void attachBaseContext(Context base) {
  33. super.attachBaseContext(base);
  34. }
  35. /**
  36. * 程序启动的时候执行
  37. */
  38. @Override
  39. public void onCreate() {
  40. Log.d("Application", "onCreate");
  41. super.onCreate();
  42. instance = this;
  43. ScreenDensityUtils.setup(this);
  44. ScreenDensityUtils.register(this,375.0f,
  45. ScreenDensityUtils.MATCH_BASE_WIDTH,ScreenDensityUtils.MATCH_UNIT_DP);
  46. if(BuildConfig.DEBUG){
  47. VideoLogUtils.setIsLog(true);
  48. }else {
  49. VideoLogUtils.setIsLog(false);
  50. }
  51. //播放器配置,注意:此为全局配置,按需开启
  52. VideoViewManager.setConfig(VideoPlayerConfig.newBuilder()
  53. .setLogEnabled(BuildConfig.DEBUG)//调试的时候请打开日志,方便排错
  54. .setPlayerFactory(IjkPlayerFactory.create())
  55. // .setPlayerFactory(ExoMediaPlayerFactory.create())
  56. // .setRenderViewFactory(SurfaceRenderViewFactory.create())
  57. // .setEnableOrientation(true)
  58. // .setEnableAudioFocus(false)
  59. // .setScreenScaleType(VideoView.SCREEN_SCALE_MATCH_PARENT)
  60. // .setAdaptCutout(false)
  61. // .setPlayOnMobileNetwork(true)
  62. // .setProgressManager(new ProgressManagerImpl())
  63. .build());
  64. }
  65. /**
  66. * 程序终止的时候执行
  67. */
  68. @Override
  69. public void onTerminate() {
  70. Log.d("Application", "onTerminate");
  71. super.onTerminate();
  72. }
  73. /**
  74. * 低内存的时候执行
  75. */
  76. @Override
  77. public void onLowMemory() {
  78. Log.d("Application", "onLowMemory");
  79. super.onLowMemory();
  80. }
  81. /**
  82. * HOME键退出应用程序
  83. * 程序在内存清理的时候执行
  84. */
  85. @Override
  86. public void onTrimMemory(int level) {
  87. Log.d("Application", "onTrimMemory");
  88. super.onTrimMemory(level);
  89. }
  90. /**
  91. * onConfigurationChanged
  92. */
  93. @Override
  94. public void onConfigurationChanged(Configuration newConfig) {
  95. Log.d("Application", "onConfigurationChanged");
  96. super.onConfigurationChanged(newConfig);
  97. }
  98. }