MediaPlayerEditor_Apple.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections.Generic;
  4. //-----------------------------------------------------------------------------
  5. // Copyright 2015-2021 RenderHeads Ltd. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. namespace RenderHeads.Media.AVProVideo.Editor
  8. {
  9. /// <summary>
  10. /// Editor for the MediaPlayer component
  11. /// </summary>
  12. public partial class MediaPlayerEditor : UnityEditor.Editor
  13. {
  14. private readonly static FieldDescription _optionAudioMode = new FieldDescription("._audioMode", new GUIContent("Audio Mode", "Unity mode does not work with HLS video"));
  15. private readonly static FieldDescription _optionTextureFormat = new FieldDescription(".textureFormat", new GUIContent("Texture Format", "BGRA32 is the most compatible.\nYCbCr420 uses ~50% of the memory of BGRA32 and has slightly better performance however it does require shader support, recommended for iOS and tvOS."));
  16. private readonly static FieldDescription _optionPreferredForwardBufferDuration = new FieldDescription("._preferredForwardBufferDuration", new GUIContent("Preferred Forward Buffer Duration", "The duration in seconds the player should buffer ahead of the playhead to prevent stalling. Set to 0 to let the system decide."));
  17. private readonly static FieldDescription _optionCustomPreferredPeakBitRateApple = new FieldDescription("._preferredPeakBitRate", new GUIContent("Preferred Peak BitRate", "The desired limit of network bandwidth consumption for playback, set to 0 for no preference."));
  18. private readonly static FieldDescription _optionCustomPreferredPeakBitRateUnitsApple = new FieldDescription("._preferredPeakBitRateUnits", new GUIContent());
  19. private void OnInspectorGUI_Override_Apple(Platform platform)
  20. {
  21. GUILayout.Space(8f);
  22. string optionsVarName = MediaPlayer.GetPlatformOptionsVariable(platform);
  23. EditorGUILayout.BeginVertical(GUI.skin.box);
  24. DisplayPlatformOption(optionsVarName, _optionTextureFormat);
  25. SerializedProperty flagsProp = serializedObject.FindProperty(optionsVarName + "._flags");
  26. MediaPlayer.OptionsApple.Flags flags = flagsProp != null ? (MediaPlayer.OptionsApple.Flags)flagsProp.intValue : 0;
  27. // Texture flags
  28. if (flagsProp != null)
  29. {
  30. bool generateMipmaps = flags.GenerateMipmaps();
  31. generateMipmaps = EditorGUILayout.Toggle(new GUIContent("Generate Mipmaps"), generateMipmaps);
  32. flags = flags.SetGenerateMipMaps(generateMipmaps);
  33. }
  34. // Audio
  35. DisplayPlatformOption(optionsVarName, _optionAudioMode);
  36. // Platform specific flags
  37. if (flagsProp != null)
  38. {
  39. if (platform == Platform.MacOSX || platform == Platform.iOS)
  40. {
  41. bool b = flags.AllowExternalPlayback();
  42. b = EditorGUILayout.Toggle(new GUIContent("Allow External Playback", "Enables support for playback on external devices via AirPlay."), b);
  43. flags = flags.SetAllowExternalPlayback(b);
  44. }
  45. if (platform == Platform.iOS)
  46. {
  47. bool b = flags.ResumePlaybackAfterAudioSessionRouteChange();
  48. b = EditorGUILayout.Toggle(new GUIContent("Resume playback after audio route change", "The default behaviour is for playback to pause when the audio route changes, for instance when disconnecting headphones."), b);
  49. flags = flags.SetResumePlaybackAfterAudioSessionRouteChange(b);
  50. }
  51. bool playWithoutBuffering = flags.PlayWithoutBuffering();
  52. playWithoutBuffering = EditorGUILayout.Toggle(new GUIContent("Play without buffering"), playWithoutBuffering);
  53. flags = flags.SetPlayWithoutBuffering(playWithoutBuffering);
  54. bool useSinglePlayerItem = flags.UseSinglePlayerItem();
  55. useSinglePlayerItem = EditorGUILayout.Toggle(new GUIContent("Use single player item", "Restricts the media player to using only one player item. This can help reduce network usage for remote videos but will cause a stall when looping."), useSinglePlayerItem);
  56. flags = flags.SetUseSinglePlayerItem(useSinglePlayerItem);
  57. }
  58. SerializedProperty maximumPlaybackRateProp = serializedObject.FindProperty(optionsVarName + ".maximumPlaybackRate");
  59. if (maximumPlaybackRateProp != null)
  60. {
  61. EditorGUILayout.Slider(maximumPlaybackRateProp, 2.0f, 10.0f, new GUIContent("Max Playback Rate", "Increase the maximum playback rate before which playback switches to key-frames only."));
  62. }
  63. GUILayout.Space(8f);
  64. EditorGUILayout.BeginVertical();
  65. EditorGUILayout.LabelField("Network", EditorStyles.boldLabel);
  66. SerializedProperty preferredMaximumResolutionProp = DisplayPlatformOption(optionsVarName, _optionPreferredMaximumResolution);
  67. if ((MediaPlayer.OptionsApple.Resolution)preferredMaximumResolutionProp.intValue == MediaPlayer.OptionsApple.Resolution.Custom)
  68. {
  69. #if UNITY_2017_2_OR_NEWER
  70. DisplayPlatformOption(optionsVarName, _optionCustomPreferredMaxResolution);
  71. #endif
  72. }
  73. EditorGUILayout.BeginHorizontal();
  74. DisplayPlatformOption(optionsVarName, _optionCustomPreferredPeakBitRateApple);
  75. DisplayPlatformOption(optionsVarName, _optionCustomPreferredPeakBitRateUnitsApple);
  76. EditorGUILayout.EndHorizontal();
  77. DisplayPlatformOption(optionsVarName, _optionPreferredForwardBufferDuration);
  78. EditorGUILayout.EndVertical();
  79. EditorGUILayout.EndVertical();
  80. // Set the flags
  81. if (flagsProp != null)
  82. {
  83. flagsProp.intValue = (int)flags;
  84. }
  85. if (_showUltraOptions)
  86. {
  87. SerializedProperty keyAuthProp = serializedObject.FindProperty(optionsVarName + ".keyAuth");
  88. if (keyAuthProp != null)
  89. {
  90. OnInspectorGUI_HlsDecryption(keyAuthProp);
  91. }
  92. SerializedProperty httpHeadersProp = serializedObject.FindProperty(optionsVarName + ".httpHeaders.httpHeaders");
  93. if (httpHeadersProp != null)
  94. {
  95. OnInspectorGUI_HttpHeaders(httpHeadersProp);
  96. }
  97. }
  98. }
  99. private void OnInspectorGUI_Override_MacOSX()
  100. {
  101. OnInspectorGUI_Override_Apple(Platform.MacOSX);
  102. }
  103. private void OnInspectorGUI_Override_iOS()
  104. {
  105. OnInspectorGUI_Override_Apple(Platform.iOS);
  106. }
  107. private void OnInspectorGUI_Override_tvOS()
  108. {
  109. OnInspectorGUI_Override_Apple(Platform.tvOS);
  110. }
  111. }
  112. }