123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- using UnityEngine;
- using UnityEditor;
- using System.Collections.Generic;
- namespace RenderHeads.Media.AVProVideo.Editor
- {
-
-
-
- public partial class MediaPlayerEditor : UnityEditor.Editor
- {
- #if UNITY_EDITOR_OSX
- internal const string MediaFileExtensions = "mp4,m4v,mov,mpg,avi,mp3,m4a,aac,ac3,au,aiff,caf,wav,m3u8";
- #else
- internal const string MediaFileExtensions = "Media Files;*.mp4;*.mov;*.m4v;*.avi;*.mkv;*.ts;*.webm;*.flv;*.vob;*.ogg;*.ogv;*.mpg;*.wmv;*.3gp;*.mxf;Audio Files;*wav;*.mp3;*.mp2;*.m4a;*.wma;*.aac;*.au;*.flac;*.m3u8;*.mpd;*.ism;";
- #endif
- private readonly static GUIContent[] _fileFormatGuiNames =
- {
- new GUIContent("Automatic (by extension)"),
- new GUIContent("Apple HLS (.m3u8)"),
- new GUIContent("MPEG-DASH (.mdp)"),
- new GUIContent("MS Smooth Streaming (.ism)"),
- };
- private SerializedProperty _propMediaSource;
- private SerializedProperty _propMediaReference;
- private SerializedProperty _propMediaPath;
- private void OnInspectorGUI_Source()
- {
-
- MediaPlayer mediaPlayer = (this.target) as MediaPlayer;
- EditorGUILayout.PropertyField(_propMediaSource);
- if (MediaSource.Reference == (MediaSource)_propMediaSource.enumValueIndex)
- {
- EditorGUILayout.PropertyField(_propMediaReference);
- }
- EditorGUILayout.BeginVertical(GUI.skin.box);
- if (MediaSource.Reference != (MediaSource)_propMediaSource.enumValueIndex)
- {
- OnInspectorGUI_CopyableFilename(mediaPlayer.MediaPath.Path);
- EditorGUILayout.PropertyField(_propMediaPath);
- }
-
- {
- GUI.color = Color.white;
- GUILayout.BeginHorizontal();
- if (_allowDeveloperMode)
- {
- if (GUILayout.Button("Rewind"))
- {
- mediaPlayer.Rewind(true);
- }
- if (GUILayout.Button("Preroll"))
- {
- mediaPlayer.RewindPrerollPause();
- }
- if (GUILayout.Button("End"))
- {
- mediaPlayer.Control.Seek(mediaPlayer.Info.GetDuration());
- }
- }
- if (GUILayout.Button("Close"))
- {
- mediaPlayer.CloseMedia();
- }
- if (GUILayout.Button("Load"))
- {
- if (mediaPlayer.MediaSource == MediaSource.Path)
- {
- mediaPlayer.OpenMedia(mediaPlayer.MediaPath.PathType, mediaPlayer.MediaPath.Path, mediaPlayer.AutoStart);
- }
- else if (mediaPlayer.MediaSource == MediaSource.Reference)
- {
- mediaPlayer.OpenMedia(mediaPlayer.MediaReference, mediaPlayer.AutoStart);
- }
- }
-
- if (EditorGUIUtility.GetObjectPickerControlID() == 100 &&
- Event.current.commandName == "ObjectSelectorClosed")
- {
- MediaReference mediaRef = (MediaReference)EditorGUIUtility.GetObjectPickerObject();
- if (mediaRef)
- {
- _propMediaSource.enumValueIndex = (int)MediaSource.Reference;
- _propMediaReference.objectReferenceValue = mediaRef;
- }
- }
- GUI.color = Color.green;
- MediaPathDrawer.ShowBrowseButtonIcon(_propMediaPath, _propMediaSource);
- GUI.color = Color.white;
- GUILayout.EndHorizontal();
-
-
- GUI.color = Color.white;
- }
- if (MediaSource.Reference != (MediaSource)_propMediaSource.enumValueIndex)
- {
- GUILayout.Label("Fallback Media Hints", EditorStyles.boldLabel);
- EditorGUILayout.PropertyField(_propFallbackMediaHints);
- }
- EditorGUILayout.EndVertical();
- }
- internal static void OnInspectorGUI_CopyableFilename(string path)
- {
- if (EditorGUIUtility.isProSkin)
- {
- GUI.backgroundColor = Color.black;
- GUI.color = Color.cyan;
- }
- EditorHelper.IMGUI.CopyableFilename(path);
- GUI.color = Color.white;
- GUI.backgroundColor = Color.white;
- }
- internal static void ShowFileWarningMessages(MediaSource mediaSource, MediaPath mediaPath, MediaReference mediaReference, bool isAutoOpen, Platform platform)
- {
- MediaPath result = null;
- if (mediaSource == MediaSource.Path)
- {
- if (mediaPath != null)
- {
- result = mediaPath;
- }
- }
- else if (mediaSource == MediaSource.Reference)
- {
- if (mediaReference != null)
- {
- result = mediaReference.GetCurrentPlatformMediaReference().MediaPath;
- }
- }
- ShowFileWarningMessages(result, isAutoOpen, platform);
- }
- internal static void ShowFileWarningMessages(string filePath, MediaPathType fileLocation, MediaReference mediaReference, MediaSource mediaSource, bool isAutoOpen, Platform platform)
- {
- MediaPath mediaPath = null;
- if (mediaSource == MediaSource.Path)
- {
- mediaPath = new MediaPath(filePath, fileLocation);
- }
- else if (mediaSource == MediaSource.Reference)
- {
- if (mediaReference != null)
- {
- mediaPath = mediaReference.GetCurrentPlatformMediaReference().MediaPath;
- }
- }
- ShowFileWarningMessages(mediaPath, isAutoOpen, platform);
- }
- internal static void ShowFileWarningMessages(MediaPath mediaPath, bool isAutoOpen, Platform platform)
- {
- string fullPath = string.Empty;
- if (mediaPath != null)
- {
- fullPath = mediaPath.GetResolvedFullPath();
- }
- if (string.IsNullOrEmpty(fullPath))
- {
- if (isAutoOpen)
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Error, "No media specified");
- }
- else
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "No media specified");
- }
- }
- else
- {
- bool isPlatformAndroid = (platform == Platform.Android) || (platform == Platform.Unknown && BuildTargetGroup.Android == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup);
- bool isPlatformIOS = (platform == Platform.iOS);
- isPlatformIOS |= (platform == Platform.Unknown && BuildTargetGroup.iOS == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup);
- bool isPlatformTVOS = (platform == Platform.tvOS);
- isPlatformTVOS |= (platform == Platform.Unknown && BuildTargetGroup.tvOS == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup);
-
- {
- bool isExtensionAVI = fullPath.ToLower().EndsWith(".avi");
- bool isExtensionMOV = fullPath.ToLower().EndsWith(".mov");
- bool isExtensionMKV = fullPath.ToLower().EndsWith(".mkv");
- if (isPlatformAndroid && isExtensionMOV)
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "MOV file detected. Android doesn't support MOV files, you should change the container file.");
- }
- if (isPlatformAndroid && isExtensionAVI)
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "AVI file detected. Android doesn't support AVI files, you should change the container file.");
- }
- if (isPlatformAndroid && isExtensionMKV)
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "MKV file detected. Android doesn't support MKV files until Android 5.0.");
- }
- if (isPlatformIOS && isExtensionAVI)
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "AVI file detected. iOS doesn't support AVI files, you should change the container file.");
- }
- }
- if (fullPath.Contains("://"))
- {
- if (fullPath.ToLower().Contains("rtmp://"))
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "RTMP protocol is not supported by AVPro Video, except when Windows DirectShow is used with an external codec library (eg LAV Filters)");
- }
- if (fullPath.ToLower().Contains("youtube.com/watch"))
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "YouTube URL detected. YouTube website URL contains no media, a direct media file URL (eg MP4 or M3U8) is required. See the documentation FAQ for YouTube support.");
- }
- if (mediaPath.PathType != MediaPathType.AbsolutePathOrURL)
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "URL detected, change location type to URL?");
- }
- else
- {
-
- if (isPlatformIOS || isPlatformTVOS)
- {
- if (!PlayerSettings.iOS.allowHTTPDownload && fullPath.StartsWith("http://"))
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "Starting with iOS 9 'allow HTTP downloads' must be enabled for HTTP connections (see Player Settings)");
- }
- }
- #if UNITY_ANDROID
- if (fullPath.StartsWith("http://"))
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "Starting with Android 8 unsecure HTTP is not allowed by default and HTTPS must be used, unless a custom cleartext security policy is assigned");
- }
- #endif
-
- if (isPlatformAndroid && !PlayerSettings.Android.forceInternetPermission)
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "You need to set 'Internet Access' to 'require' in your Player Settings for Android builds when using URLs");
- }
-
- if (platform == Platform.WindowsUWP || (platform == Platform.Unknown && (
- BuildTargetGroup.WSA == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup
- )))
- {
- if (!PlayerSettings.WSA.GetCapability(PlayerSettings.WSACapability.InternetClient))
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "You need to set 'InternetClient' capability in your Player Settings when using URLs");
- }
- }
- }
- }
- else
- {
-
- #if !UNITY_EDITOR_OSX
- if (mediaPath.PathType != MediaPathType.AbsolutePathOrURL && fullPath.StartsWith("/"))
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "Absolute path detected, change location to Absolute path?");
- }
- #endif
-
- if (isPlatformAndroid && !PlayerSettings.Android.forceSDCardPermission)
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "You may need to access the local file system you may need to set 'Write Access' to 'External(SDCard)' in your Player Settings for Android");
- }
- if (platform == Platform.Unknown || platform == MediaPlayer.GetPlatform())
- {
- if (!System.IO.File.Exists(fullPath))
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Error, "File not found");
- }
- else
- {
-
-
- if (!Application.isPlaying)
- {
- string comparePath = fullPath.Replace('\\', '/');
- string folderPath = System.IO.Path.GetDirectoryName(comparePath);
- if (!string.IsNullOrEmpty(folderPath))
- {
- string[] files = System.IO.Directory.GetFiles(folderPath, "*", System.IO.SearchOption.TopDirectoryOnly);
- bool caseMatch = false;
- if (files != null && files.Length > 0)
- {
- for (int i = 0; i < files.Length; i++)
- {
- if (files[i].Replace('\\', '/') == comparePath)
- {
- caseMatch = true;
- break;
- }
- }
- }
- if (!caseMatch)
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "File found but case doesn't match");
- }
- }
- }
- }
- }
- }
- }
- if (mediaPath != null && mediaPath.PathType == MediaPathType.RelativeToStreamingAssetsFolder)
- {
- if (!System.IO.Directory.Exists(Application.streamingAssetsPath))
- {
- GUILayout.BeginHorizontal();
- GUI.color = Color.yellow;
- GUILayout.TextArea("Warning: No StreamingAssets folder found");
- if (GUILayout.Button("Create Folder"))
- {
- System.IO.Directory.CreateDirectory(Application.streamingAssetsPath);
- AssetDatabase.Refresh();
- }
- GUILayout.EndHorizontal();
- }
- else
- {
- bool checkAndroidFileSize = false;
- #if UNITY_ANDROID
- if (platform == Platform.Unknown)
- {
- checkAndroidFileSize = true;
- }
- #endif
- if (platform == Platform.Android)
- {
- checkAndroidFileSize = true;
- }
- if (checkAndroidFileSize)
- {
- try
- {
- System.IO.FileInfo info = new System.IO.FileInfo(fullPath);
- if (info != null && info.Length > (1024 * 1024 * 512))
- {
- EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "Using this very large file inside StreamingAssets folder on Android isn't recommended. Deployments will be slow and mapping the file from the StreamingAssets JAR may cause storage and memory issues. We recommend loading from another folder on the device.");
- }
- }
- catch (System.Exception)
- {
- }
- }
- }
- }
- GUI.color = Color.white;
- }
- }
- }
|