NullMediaPlayer.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. using System;
  2. using System.Text;
  3. using UnityEngine;
  4. //-----------------------------------------------------------------------------
  5. // Copyright 2015-2021 RenderHeads Ltd. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. namespace RenderHeads.Media.AVProVideo
  8. {
  9. /// <summary>
  10. /// This media player fakes video playback for platforms that aren't supported
  11. /// </summary>
  12. public sealed partial class NullMediaPlayer : BaseMediaPlayer
  13. {
  14. private bool _isPlaying = false;
  15. private bool _isPaused = false;
  16. private double _currentTime = 0.0;
  17. // private bool _audioMuted = false;
  18. private float _volume = 0.0f;
  19. private float _playbackRate = 1.0f;
  20. private bool _bLoop;
  21. private int _Width = 256;
  22. private int _height = 256;
  23. private Texture2D _texture;
  24. private Texture2D _texture_AVPro;
  25. private Texture2D _texture_AVPro1;
  26. private float _fakeFlipTime;
  27. private int _frameCount;
  28. private const float FrameRate = 10f;
  29. /// <inheritdoc/>
  30. public override string GetVersion()
  31. {
  32. return "0.0.0";
  33. }
  34. /// <inheritdoc/>
  35. public override string GetExpectedVersion()
  36. {
  37. return GetVersion();
  38. }
  39. /// <inheritdoc/>
  40. public override bool OpenMedia(string path, long offset, string httpHeader, MediaHints mediaHints, int forceFileFormat = 0, bool startWithHighestBitrate = false)
  41. {
  42. _texture_AVPro = (Texture2D)Resources.Load("Textures/AVProVideo-NullPlayer-Frame0");
  43. _texture_AVPro1 = (Texture2D)Resources.Load("Textures/AVProVideo-NullPlayer-Frame1");
  44. if( _texture_AVPro )
  45. {
  46. _Width = _texture_AVPro.width;
  47. _height = _texture_AVPro.height;
  48. }
  49. _texture = _texture_AVPro;
  50. _fakeFlipTime = 0.0f;
  51. _frameCount = 0;
  52. return true;
  53. }
  54. /// <inheritdoc/>
  55. public override void CloseMedia()
  56. {
  57. _frameCount = 0;
  58. Resources.UnloadAsset(_texture_AVPro);
  59. Resources.UnloadAsset(_texture_AVPro1);
  60. base.CloseMedia();
  61. }
  62. /// <inheritdoc/>
  63. public override void SetLooping( bool bLooping )
  64. {
  65. _bLoop = bLooping;
  66. }
  67. /// <inheritdoc/>
  68. public override bool IsLooping()
  69. {
  70. return _bLoop;
  71. }
  72. /// <inheritdoc/>
  73. public override bool HasMetaData()
  74. {
  75. return true;
  76. }
  77. /// <inheritdoc/>
  78. public override bool CanPlay()
  79. {
  80. return true;
  81. }
  82. /// <inheritdoc/>
  83. public override bool HasAudio()
  84. {
  85. return false;
  86. }
  87. /// <inheritdoc/>
  88. public override bool HasVideo()
  89. {
  90. return false;
  91. }
  92. /// <inheritdoc/>
  93. public override void Play()
  94. {
  95. _isPlaying = true;
  96. _isPaused = false;
  97. _fakeFlipTime = 0.0f;
  98. }
  99. /// <inheritdoc/>
  100. public override void Pause()
  101. {
  102. _isPlaying = false;
  103. _isPaused = true;
  104. }
  105. /// <inheritdoc/>
  106. public override void Stop()
  107. {
  108. _isPlaying = false;
  109. _isPaused = false;
  110. }
  111. /// <inheritdoc/>
  112. public override bool IsSeeking()
  113. {
  114. return false;
  115. }
  116. /// <inheritdoc/>
  117. public override bool IsPlaying()
  118. {
  119. return _isPlaying;
  120. }
  121. /// <inheritdoc/>
  122. public override bool IsPaused()
  123. {
  124. return _isPaused;
  125. }
  126. /// <inheritdoc/>
  127. public override bool IsFinished()
  128. {
  129. return _isPlaying && (_currentTime >= GetDuration());
  130. }
  131. /// <inheritdoc/>
  132. public override bool IsBuffering()
  133. {
  134. return false;
  135. }
  136. /// <inheritdoc/>
  137. public override double GetDuration()
  138. {
  139. return 10.0;
  140. }
  141. /// <inheritdoc/>
  142. public override int GetVideoWidth()
  143. {
  144. return _Width;
  145. }
  146. /// <inheritdoc/>
  147. public override int GetVideoHeight()
  148. {
  149. return _height;
  150. }
  151. /// <inheritdoc/>
  152. public override float GetVideoDisplayRate()
  153. {
  154. return FrameRate;
  155. }
  156. /// <inheritdoc/>
  157. public override Texture GetTexture( int index )
  158. {
  159. // return _texture ? _texture : Texture2D.whiteTexture;
  160. return _texture;
  161. }
  162. /// <inheritdoc/>
  163. public override int GetTextureFrameCount()
  164. {
  165. return _frameCount;
  166. }
  167. internal override StereoPacking InternalGetTextureStereoPacking()
  168. {
  169. return StereoPacking.Unknown;
  170. }
  171. /// <inheritdoc/>
  172. public override bool RequiresVerticalFlip()
  173. {
  174. return false;
  175. }
  176. /// <inheritdoc/>
  177. public override void Seek(double time)
  178. {
  179. _currentTime = time;
  180. }
  181. /// <inheritdoc/>
  182. public override void SeekFast(double time)
  183. {
  184. _currentTime = time;
  185. }
  186. /// <inheritdoc/>
  187. public override double GetCurrentTime()
  188. {
  189. return _currentTime;
  190. }
  191. /// <inheritdoc/>
  192. public override void SetPlaybackRate(float rate)
  193. {
  194. _playbackRate = rate;
  195. }
  196. /// <inheritdoc/>
  197. public override float GetPlaybackRate()
  198. {
  199. return _playbackRate;
  200. }
  201. /// <inheritdoc/>
  202. public override void MuteAudio(bool bMuted)
  203. {
  204. // _audioMuted = bMuted;
  205. }
  206. /// <inheritdoc/>
  207. public override bool IsMuted()
  208. {
  209. return true;
  210. }
  211. /// <inheritdoc/>
  212. public override void SetVolume(float volume)
  213. {
  214. _volume = volume;
  215. }
  216. /// <inheritdoc/>
  217. public override float GetVolume()
  218. {
  219. return _volume;
  220. }
  221. /// <inheritdoc/>
  222. public override float GetVideoFrameRate()
  223. {
  224. return 0.0f;
  225. }
  226. /// <inheritdoc/>
  227. public override void Update()
  228. {
  229. UpdateSubtitles();
  230. if (_isPlaying)
  231. {
  232. _currentTime += Time.deltaTime;
  233. if (_currentTime >= GetDuration())
  234. {
  235. _currentTime = GetDuration();
  236. if( _bLoop )
  237. {
  238. Rewind();
  239. }
  240. }
  241. //
  242. _fakeFlipTime += Time.deltaTime;
  243. if( _fakeFlipTime >= (1.0 / FrameRate))
  244. {
  245. _fakeFlipTime = 0.0f;
  246. _texture = ( _texture == _texture_AVPro ) ? _texture_AVPro1 : _texture_AVPro;
  247. _frameCount++;
  248. }
  249. }
  250. }
  251. /// <inheritdoc/>
  252. public override void Render()
  253. {
  254. }
  255. /// <inheritdoc/>
  256. public override void Dispose()
  257. {
  258. }
  259. }
  260. public sealed partial class NullMediaPlayer : BaseMediaPlayer
  261. {
  262. internal override bool InternalSetActiveTrack(TrackType trackType, int trackUid)
  263. {
  264. // Set the active text track using the unique identifier
  265. // Or disable all text tracks if < 0
  266. return false;
  267. }
  268. internal override bool InternalIsChangedTracks(TrackType trackType)
  269. {
  270. // Has the tracks changed since the last frame 'tick'
  271. return false;
  272. }
  273. internal override int InternalGetTrackCount(TrackType trackType)
  274. {
  275. // Return number of text tracks
  276. return 0;
  277. }
  278. internal override TrackBase InternalGetTrackInfo(TrackType trackType, int index, ref bool isActiveTrack)
  279. {
  280. // Get information about the specific track at index, range is [0...InternalGetTextTrackCount)
  281. return null;
  282. }
  283. internal override bool InternalIsChangedTextCue()
  284. {
  285. // Has the text cue changed since the last frame 'tick'
  286. return false;
  287. }
  288. internal override string InternalGetCurrentTextCue()
  289. {
  290. return null;
  291. }
  292. }
  293. }