NullMediaPlayer.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using System;
  2. using UnityEngine;
  3. //-----------------------------------------------------------------------------
  4. // Copyright 2015-2020 RenderHeads Ltd. All rights reserved.
  5. //-----------------------------------------------------------------------------
  6. namespace RenderHeads.Media.AVProVideo
  7. {
  8. /// <summary>
  9. /// This media player fakes video playback for platforms that aren't supported
  10. /// </summary>
  11. public sealed class NullMediaPlayer : BaseMediaPlayer
  12. {
  13. private bool _isPlaying = false;
  14. private bool _isPaused = false;
  15. private float _currentTime = 0.0f;
  16. // private bool _audioMuted = false;
  17. private float _volume = 0.0f;
  18. private float _playbackRate = 1.0f;
  19. private bool _bLoop;
  20. private int _Width = 256;
  21. private int _height = 256;
  22. private Texture2D _texture;
  23. private Texture2D _texture_AVPro;
  24. private Texture2D _texture_AVPro1;
  25. private float _fakeFlipTime;
  26. private int _frameCount;
  27. private const float FrameRate = 10f;
  28. public override string GetVersion()
  29. {
  30. return "0.0.0";
  31. }
  32. public override bool OpenVideoFromFile(string path, long offset, string httpHeaderJson, uint sourceSamplerate = 0, uint sourceChannels = 0, int forceFileFormat = 0)
  33. {
  34. _texture_AVPro = (Texture2D)Resources.Load("AVPro");
  35. _texture_AVPro1 = (Texture2D)Resources.Load("AVPro1");
  36. if (_texture_AVPro)
  37. {
  38. _Width = _texture_AVPro.width;
  39. _height = _texture_AVPro.height;
  40. }
  41. _texture = _texture_AVPro;
  42. _fakeFlipTime = 0.0f;
  43. _frameCount = 0;
  44. return true;
  45. }
  46. public override void CloseVideo()
  47. {
  48. _frameCount = 0;
  49. Resources.UnloadAsset(_texture_AVPro);
  50. Resources.UnloadAsset(_texture_AVPro1);
  51. base.CloseVideo();
  52. }
  53. public override void SetLooping(bool bLooping)
  54. {
  55. _bLoop = bLooping;
  56. }
  57. public override bool IsLooping()
  58. {
  59. return _bLoop;
  60. }
  61. public override bool HasMetaData()
  62. {
  63. return true;
  64. }
  65. public override bool CanPlay()
  66. {
  67. return true;
  68. }
  69. public override bool HasAudio()
  70. {
  71. return false;
  72. }
  73. public override bool HasVideo()
  74. {
  75. return false;
  76. }
  77. public override void Play()
  78. {
  79. _isPlaying = true;
  80. _isPaused = false;
  81. _fakeFlipTime = 0.0f;
  82. }
  83. public override void Pause()
  84. {
  85. _isPlaying = false;
  86. _isPaused = true;
  87. }
  88. public override void Stop()
  89. {
  90. _isPlaying = false;
  91. _isPaused = false;
  92. }
  93. public override bool IsSeeking()
  94. {
  95. return false;
  96. }
  97. public override bool IsPlaying()
  98. {
  99. return _isPlaying;
  100. }
  101. public override bool IsPaused()
  102. {
  103. return _isPaused;
  104. }
  105. public override bool IsFinished()
  106. {
  107. return _isPlaying && (_currentTime >= GetDurationMs());
  108. }
  109. public override bool IsBuffering()
  110. {
  111. return false;
  112. }
  113. public override float GetDurationMs()
  114. {
  115. return 10.0f * 1000.0f;
  116. }
  117. public override int GetVideoWidth()
  118. {
  119. return _Width;
  120. }
  121. public override int GetVideoHeight()
  122. {
  123. return _height;
  124. }
  125. public override float GetVideoDisplayRate()
  126. {
  127. return FrameRate;
  128. }
  129. public override Texture GetTexture(int index)
  130. {
  131. // return _texture ? _texture : Texture2D.whiteTexture;
  132. return _texture;
  133. }
  134. public override int GetTextureFrameCount()
  135. {
  136. return _frameCount;
  137. }
  138. public override bool RequiresVerticalFlip()
  139. {
  140. return false;
  141. }
  142. public override void Seek(float timeMs)
  143. {
  144. _currentTime = timeMs;
  145. }
  146. public override void SeekFast(float timeMs)
  147. {
  148. _currentTime = timeMs;
  149. }
  150. public override void SeekWithTolerance(float timeMs, float beforeMs, float afterMs)
  151. {
  152. _currentTime = timeMs;
  153. }
  154. public override float GetCurrentTimeMs()
  155. {
  156. return _currentTime;
  157. }
  158. public override void SetPlaybackRate(float rate)
  159. {
  160. _playbackRate = rate;
  161. }
  162. public override float GetPlaybackRate()
  163. {
  164. return _playbackRate;
  165. }
  166. public override float GetBufferingProgress()
  167. {
  168. return 0f;
  169. }
  170. public override void MuteAudio(bool bMuted)
  171. {
  172. // _audioMuted = bMuted;
  173. }
  174. public override bool IsMuted()
  175. {
  176. return true;
  177. }
  178. public override void SetVolume(float volume)
  179. {
  180. _volume = volume;
  181. }
  182. public override float GetVolume()
  183. {
  184. return _volume;
  185. }
  186. public override int GetAudioTrackCount()
  187. {
  188. return 0;
  189. }
  190. public override int GetCurrentAudioTrack()
  191. {
  192. return 0;
  193. }
  194. public override void SetAudioTrack(int index)
  195. {
  196. }
  197. public override int GetVideoTrackCount()
  198. {
  199. return 0;
  200. }
  201. public override int GetCurrentVideoTrack()
  202. {
  203. return 0;
  204. }
  205. public override string GetCurrentAudioTrackId()
  206. {
  207. // TODO
  208. return "";
  209. }
  210. public override int GetCurrentAudioTrackBitrate()
  211. {
  212. // TODO
  213. return 0;
  214. }
  215. public override void SetVideoTrack(int index)
  216. {
  217. }
  218. public override string GetCurrentVideoTrackId()
  219. {
  220. return "";
  221. }
  222. public override int GetCurrentVideoTrackBitrate()
  223. {
  224. return 0;
  225. }
  226. public override float GetVideoFrameRate()
  227. {
  228. return 0.0f;
  229. }
  230. public override void Update()
  231. {
  232. UpdateSubtitles();
  233. if (_isPlaying)
  234. {
  235. _currentTime += Time.deltaTime * 1000.0f;
  236. if (_currentTime >= GetDurationMs())
  237. {
  238. _currentTime = GetDurationMs();
  239. if (_bLoop)
  240. {
  241. Rewind();
  242. }
  243. }
  244. //
  245. _fakeFlipTime += Time.deltaTime;
  246. if (_fakeFlipTime >= (1.0 / FrameRate))
  247. {
  248. _fakeFlipTime = 0.0f;
  249. _texture = (_texture == _texture_AVPro) ? _texture_AVPro1 : _texture_AVPro;
  250. _frameCount++;
  251. }
  252. }
  253. }
  254. public override void Render()
  255. {
  256. }
  257. public override void Dispose()
  258. {
  259. }
  260. }
  261. }