MediaPlayer_AppFocus.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #if !(UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_TVOS)
  2. using UnityEngine;
  3. //-----------------------------------------------------------------------------
  4. // Copyright 2015-2022 RenderHeads Ltd. All rights reserved.
  5. //-----------------------------------------------------------------------------
  6. namespace RenderHeads.Media.AVProVideo
  7. {
  8. public partial class MediaPlayer : MonoBehaviour
  9. {
  10. #region Application Focus and Pausing
  11. #if !UNITY_EDITOR
  12. void OnApplicationFocus(bool focusStatus)
  13. {
  14. #if !(UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
  15. // Debug.Log("OnApplicationFocus: focusStatus: " + focusStatus);
  16. if (focusStatus)
  17. {
  18. if (Control != null && _wasPlayingOnPause)
  19. {
  20. _wasPlayingOnPause = false;
  21. Control.Play();
  22. Helper.LogInfo("OnApplicationFocus: playing video again");
  23. }
  24. }
  25. #endif
  26. }
  27. void OnApplicationPause(bool pauseStatus)
  28. {
  29. #if !(UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
  30. // Debug.Log("OnApplicationPause: pauseStatus: " + pauseStatus);
  31. if (pauseStatus)
  32. {
  33. if (_pauseMediaOnAppPause)
  34. {
  35. if (Control!= null && Control.IsPlaying())
  36. {
  37. _wasPlayingOnPause = true;
  38. #if !UNITY_IPHONE
  39. Control.Pause();
  40. #endif
  41. Helper.LogInfo("OnApplicationPause: pausing video");
  42. }
  43. }
  44. }
  45. else
  46. {
  47. if (_playMediaOnAppUnpause)
  48. {
  49. // Catch coming back from power off state when no lock screen
  50. OnApplicationFocus(true);
  51. }
  52. }
  53. #endif
  54. }
  55. #endif
  56. #endregion // Application Focus and Pausing
  57. }
  58. }
  59. #endif