UMPSmoothRewind.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace UMP
  4. {
  5. public class UMPSmoothRewind : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private UniversalMediaPlayer _mediaPlayer = null;
  9. [SerializeField]
  10. private Slider _rewindSlider = null;
  11. private long _framesCounterCahce;
  12. private void Update()
  13. {
  14. if (_mediaPlayer.PlatformPlayer is MediaPlayerStandalone)
  15. {
  16. if (_mediaPlayer.IsPlaying && _framesCounterCahce != _mediaPlayer.FramesCounter)
  17. {
  18. _framesCounterCahce = _mediaPlayer.FramesCounter;
  19. var frameAmount = (_mediaPlayer.PlatformPlayer as MediaPlayerStandalone).FramesAmount;
  20. if (frameAmount > 0)
  21. _rewindSlider.value = (float)_framesCounterCahce / frameAmount;
  22. }
  23. }
  24. }
  25. public void OnPositionChanged()
  26. {
  27. _mediaPlayer.Position = _rewindSlider.value;
  28. }
  29. }
  30. }