MediaPlayerCacheManager.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. namespace Agora.Rtc
  3. {
  4. public class MediaPlayerCacheManager : IMediaPlayerCacheManager
  5. {
  6. private IRtcEngine _rtcEngineInstance = null;
  7. private MediaPlayerCacheManagerImpl _mediaPlayerCacheManagerImpl = null;
  8. private const int ErrorCode = -7;
  9. private MediaPlayerCacheManager(IRtcEngine rtcEngine, MediaPlayerCacheManagerImpl impl)
  10. {
  11. _rtcEngineInstance = rtcEngine;
  12. _mediaPlayerCacheManagerImpl = impl;
  13. }
  14. ~MediaPlayerCacheManager()
  15. {
  16. _rtcEngineInstance = null;
  17. }
  18. private static MediaPlayerCacheManager instance = null;
  19. public static MediaPlayerCacheManager Instance
  20. {
  21. get
  22. {
  23. return instance;
  24. }
  25. }
  26. internal static MediaPlayerCacheManager GetInstance(IRtcEngine rtcEngine, MediaPlayerCacheManagerImpl impl)
  27. {
  28. return instance ?? (instance = new MediaPlayerCacheManager(rtcEngine, impl));
  29. }
  30. internal static void ReleaseInstance()
  31. {
  32. instance = null;
  33. }
  34. public override int RemoveAllCaches()
  35. {
  36. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  37. {
  38. return ErrorCode;
  39. }
  40. return _mediaPlayerCacheManagerImpl.RemoveAllCaches();
  41. }
  42. public override int RemoveOldCache()
  43. {
  44. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  45. {
  46. return ErrorCode;
  47. }
  48. return _mediaPlayerCacheManagerImpl.RemoveOldCache();
  49. }
  50. public override int RemoveCacheByUri(string uri)
  51. {
  52. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  53. {
  54. return ErrorCode;
  55. }
  56. return _mediaPlayerCacheManagerImpl.RemoveCacheByUri(uri);
  57. }
  58. public override int SetCacheDir(string path)
  59. {
  60. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  61. {
  62. return ErrorCode;
  63. }
  64. return _mediaPlayerCacheManagerImpl.SetCacheDir(path);
  65. }
  66. public override int SetMaxCacheFileCount(int count)
  67. {
  68. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  69. {
  70. return ErrorCode;
  71. }
  72. return _mediaPlayerCacheManagerImpl.SetMaxCacheFileCount(count);
  73. }
  74. public override int SetMaxCacheFileSize(long cacheSize)
  75. {
  76. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  77. {
  78. return ErrorCode;
  79. }
  80. return _mediaPlayerCacheManagerImpl.SetMaxCacheFileSize(cacheSize);
  81. }
  82. public override int EnableAutoRemoveCache(bool enable)
  83. {
  84. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  85. {
  86. return ErrorCode;
  87. }
  88. return _mediaPlayerCacheManagerImpl.EnableAutoRemoveCache(enable);
  89. }
  90. public override int GetCacheDir(out string path, int length)
  91. {
  92. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  93. {
  94. path = "";
  95. return ErrorCode;
  96. }
  97. return _mediaPlayerCacheManagerImpl.GetCacheDir(out path, length);
  98. }
  99. public override int GetMaxCacheFileCount()
  100. {
  101. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  102. {
  103. return ErrorCode;
  104. }
  105. return _mediaPlayerCacheManagerImpl.GetMaxCacheFileCount();
  106. }
  107. public override long GetMaxCacheFileSize()
  108. {
  109. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  110. {
  111. return ErrorCode;
  112. }
  113. return _mediaPlayerCacheManagerImpl.GetMaxCacheFileSize();
  114. }
  115. public override int GetCacheFileCount()
  116. {
  117. if (_rtcEngineInstance == null || _mediaPlayerCacheManagerImpl == null)
  118. {
  119. return ErrorCode;
  120. }
  121. return _mediaPlayerCacheManagerImpl.GetCacheFileCount();
  122. }
  123. }
  124. }