BaseApplication.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package com.yc.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.factory.PlayerFactory;
  7. import com.yc.kernel.utils.PlayerConstant;
  8. import com.yc.kernel.utils.PlayerFactoryUtils;
  9. import com.yc.video.config.VideoPlayerConfig;
  10. import com.yc.video.player.VideoViewManager;
  11. import com.yc.video.surface.SurfaceViewFactory;
  12. /**
  13. * ================================================
  14. * 作 者:杨充
  15. * 版 本:1.0
  16. * 创建日期:2017/8/18
  17. * 描 述:BaseApplication
  18. * 修订历史:
  19. * ================================================
  20. */
  21. public class BaseApplication extends Application {
  22. private static BaseApplication instance;
  23. public static synchronized BaseApplication getInstance() {
  24. if (null == instance) {
  25. instance = new BaseApplication();
  26. }
  27. return instance;
  28. }
  29. public BaseApplication(){}
  30. /**
  31. * 这个最先执行
  32. */
  33. @Override
  34. protected void attachBaseContext(Context base) {
  35. super.attachBaseContext(base);
  36. }
  37. /**
  38. * 程序启动的时候执行
  39. */
  40. @Override
  41. public void onCreate() {
  42. Log.d("Application", "onCreate");
  43. super.onCreate();
  44. instance = this;
  45. ScreenDensityUtils.setup(this);
  46. ScreenDensityUtils.register(this,375.0f,
  47. ScreenDensityUtils.MATCH_BASE_WIDTH,ScreenDensityUtils.MATCH_UNIT_DP);
  48. //播放器配置,注意:此为全局配置,按需开启
  49. PlayerFactory player = PlayerFactoryUtils.getPlayer(PlayerConstant.PlayerType.TYPE_IJK);
  50. VideoViewManager.setConfig(VideoPlayerConfig.newBuilder()
  51. //设置上下文
  52. .setContext(this)
  53. //设置视频全局埋点事件
  54. .setBuriedPointEvent(new BuriedPointEventImpl())
  55. //调试的时候请打开日志,方便排错
  56. .setLogEnabled(true)
  57. //设置ijk
  58. .setPlayerFactory(player)
  59. //创建SurfaceView
  60. //.setRenderViewFactory(SurfaceViewFactory.create())
  61. .build());
  62. }
  63. /**
  64. * 程序终止的时候执行
  65. */
  66. @Override
  67. public void onTerminate() {
  68. Log.d("Application", "onTerminate");
  69. super.onTerminate();
  70. }
  71. /**
  72. * 低内存的时候执行
  73. */
  74. @Override
  75. public void onLowMemory() {
  76. Log.d("Application", "onLowMemory");
  77. super.onLowMemory();
  78. }
  79. /**
  80. * HOME键退出应用程序
  81. * 程序在内存清理的时候执行
  82. */
  83. @Override
  84. public void onTrimMemory(int level) {
  85. Log.d("Application", "onTrimMemory");
  86. super.onTrimMemory(level);
  87. }
  88. /**
  89. * onConfigurationChanged
  90. */
  91. @Override
  92. public void onConfigurationChanged(Configuration newConfig) {
  93. Log.d("Application", "onConfigurationChanged");
  94. super.onConfigurationChanged(newConfig);
  95. }
  96. }