private static string GetStartFolder(string path, MediaPlayer.FileLocation fileLocation) { // Try to resolve based on file path + file location string result = MediaPlayer.GetFilePath(path, fileLocation); if (!string.IsNullOrEmpty(result)) { if (System.IO.File.Exists(result)) { result = System.IO.Path.GetDirectoryName(result); } } if (!System.IO.Directory.Exists(result)) { // Just resolve on file location result = MediaPlayer.GetPath(fileLocation); } if (string.IsNullOrEmpty(result)) { // Fallback result = Application.streamingAssetsPath; } return(result); }
private void LoadVideo(string filePath, bool url = false) { // Set the video file name and to load. if (!url) { _nextVideoLocation = MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder; } else { _nextVideoLocation = MediaPlayer.FileLocation.AbsolutePathOrURL; } _nextVideoPath = filePath; // IF we're not using fading then load the video immediately if (!_useFading) { // Load the video if (!_mediaPlayer.OpenVideoFromFile(_nextVideoLocation, _nextVideoPath, _mediaPlayer.m_AutoStart)) { Debug.LogError("Failed to open video!"); } } else { StartCoroutine("LoadVideoWithFading"); } }
/// <summary> /// Read all music from directory. /// </summary> public void ReadBGM(MediaPlayer.FileLocation musicLocation) { string pathLocation = string.Empty; switch (musicLocation) { case MediaPlayer.FileLocation.AbsolutePathOrURL: break; case MediaPlayer.FileLocation.RelativeToProjectFolder: #if !UNITY_WINRT_8_1 pathLocation = Path.GetFullPath(Path.Combine(Application.dataPath, "..")); pathLocation = pathLocation.Replace('\\', '/'); #endif break; case MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder: pathLocation = Application.streamingAssetsPath; break; case MediaPlayer.FileLocation.RelativeToDataFolder: pathLocation = Application.dataPath; break; case MediaPlayer.FileLocation.RelativeToPeristentDataFolder: pathLocation = Application.persistentDataPath; break; default: break; } _pathBGM = pathLocation + @"/" + BGMDirectoryName; try { _bgmTypes = FileManager.Instance.GetDirectoryName(_pathBGM); _bgmList = new List <string[]>(); int typeTotalNum = _bgmTypes.Count; for (int i = 0; i < typeTotalNum; i++) { string path = _pathBGM + @"/" + _bgmTypes[i]; string[] nameList = FileManager.Instance.GetFileName(path, "*.mp3").ToArray(); if (nameList.Length == 0) { _bgmTypes.RemoveAt(i); } else { _bgmList.Add(nameList); } } } catch (System.Exception e) { Debug.Log(e.Message); throw; } }
void RecentMenuCallback_Select(object obj) { RecentFileData data = (RecentFileData)obj; string videoPath = string.Empty; MediaPlayer.FileLocation fileLocation = MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder; GetRelativeLocationFromPath(data.path, ref videoPath, ref fileLocation); data.propPath.stringValue = videoPath; data.propLocation.enumValueIndex = (int)fileLocation; serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(data.target); }
private void GUI_OverridePath(int platformIndex) { SerializedProperty location = serializedObject.FindProperty("m_platformVideoLocation"); SerializedProperty propLocation = location.GetArrayElementAtIndex(platformIndex); EditorGUILayout.PropertyField(propLocation, new GUIContent("Location")); SerializedProperty path = serializedObject.FindProperty("m_platformVideoPath"); SerializedProperty propPath = path.GetArrayElementAtIndex(platformIndex); EditorGUILayout.PropertyField(propPath, new GUIContent("Video Path")); GUILayout.BeginHorizontal(); OnInspectorGUI_RecentButton(propPath, propLocation); GUI.color = Color.green; if (GUILayout.Button("BROWSE")) { string result = string.Empty; MediaPlayer.FileLocation fileLocation = MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder; string startFolder = GetStartFolder(propPath.stringValue, (MediaPlayer.FileLocation)propLocation.enumValueIndex); string fullPath = string.Empty; if (Browse(startFolder, ref result, ref fileLocation, ref fullPath)) { propPath.stringValue = result; propLocation.enumValueIndex = (int)fileLocation; EditorUtility.SetDirty(target); } } GUILayout.EndHorizontal(); GUI.color = Color.white; // Display the file name so it's easy to read and copy to the clipboard MediaPlayer media = (this.target) as MediaPlayer; OnInspectorGUI_CopyableFilename(media.m_platformVideoPath[platformIndex]); if (GUI.enabled) { ShowFileWarningMessages(propPath.stringValue, (MediaPlayer.FileLocation)propLocation.enumValueIndex, false, (Platform)platformIndex); } }
private static bool Browse(string startPath, ref string filePath, ref MediaPlayer.FileLocation fileLocation, ref string fullPath) { bool result = false; #if UNITY_EDITOR_OSX string extensions = "mp4,m4v,mov,avi"; extensions += ",mp3,m4a,aac,ac3,au,aiff,wav"; #else string extensions = "Media Files;*.mp4;*.mov;*.m4v;*.avi;*.mkv;*.ts;*.webm;*.flv;*.vob;*.ogg;*.ogv;*.mpg;*.wmv;*.3gp"; extensions += ";Audio Files;*wav;*.mp3;*.mp2;*.m4a;*.wma;*.aac;*.au;*.flac"; #endif string path = UnityEditor.EditorUtility.OpenFilePanel("Browse Video File", startPath, extensions); if (!string.IsNullOrEmpty(path) && !path.EndsWith(".meta")) { fullPath = path; GetRelativeLocationFromPath(path, ref filePath, ref fileLocation); result = true; } return(result); }
private static void ShowFileWarningMessages(string filePath, MediaPlayer.FileLocation fileLocation, bool isAutoOpen, Platform platform) { string finalPath = MediaPlayer.GetFilePath(filePath, fileLocation); if (string.IsNullOrEmpty(filePath)) { if (isAutoOpen) { GUI.color = Color.red; GUILayout.TextArea("Error: No file specfied"); GUI.color = Color.white; } else { GUI.color = Color.yellow; GUILayout.TextArea("Warning: No file specfied"); GUI.color = Color.white; } } else { if (finalPath.Contains("://")) { if (fileLocation != MediaPlayer.FileLocation.AbsolutePathOrURL) { GUI.color = Color.yellow; GUILayout.TextArea("Warning: URL detected, change location to URL?"); GUI.color = Color.white; } else { #if AVPRO_UNITY_IOS_ALLOWHTTPDOWNLOAD // Display warning to iOS users if they're trying to use HTTP url without setting the permission bool isPlatformIOS = (platform == Platform.iOS) || (platform == Platform.Unknown && BuildTargetGroup.iOS == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup); #if AVPRO_UNITY_PLATFORM_TVOS isPlatformIOS |= (platform == Platform.tvOS) || (platform == Platform.Unknown && BuildTargetGroup.tvOS == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup); #endif if (isPlatformIOS) { if (filePath.StartsWith("http://") && !PlayerSettings.iOS.allowHTTPDownload) { GUI.color = Color.yellow; GUILayout.TextArea("Warning: Starting with iOS 9 'allow HTTP downloads' must be enabled for HTTP connections (see Player Settings)"); GUI.color = Color.white; } } #endif // Display warning for Andorid users if they're trying to use a URL without setting permission if (platform == Platform.Android || (platform == Platform.Unknown && BuildTargetGroup.Android == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup)) { if (!PlayerSettings.Android.forceInternetPermission) { GUI.color = Color.yellow; GUILayout.TextArea("Warning: You may need to set 'Internet Access' to 'require' in your Player Settings for Android builds when using URLs"); GUI.color = Color.white; } } } } else { if (platform == Platform.Unknown || platform == MediaPlayer.GetPlatform()) { if (!System.IO.File.Exists(finalPath)) { GUI.color = Color.red; GUILayout.TextArea("Error: File not found"); GUI.color = Color.white; } } } } if (fileLocation == MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder) { if (!System.IO.Directory.Exists(Application.streamingAssetsPath)) { GUILayout.Space(10f); GUILayout.BeginHorizontal(); GUI.color = Color.yellow; GUILayout.TextArea("Warning: No StreamingAssets folder found"); GUI.color = Color.white; if (GUILayout.Button("Create Folder")) { System.IO.Directory.CreateDirectory(Application.streamingAssetsPath); AssetDatabase.Refresh(); } GUILayout.EndHorizontal(); } } GUI.color = Color.white; }
public override void OnInspectorGUI() { MediaPlayer media = (this.target) as MediaPlayer; //DrawDefaultInspector(); serializedObject.Update(); GUILayout.Space(6f); /////////////////// FILE PATH EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField("File", EditorStyles.boldLabel); GUI.enabled = !Application.isPlaying; SerializedProperty propLocation = serializedObject.FindProperty("m_VideoLocation"); EditorGUILayout.PropertyField(propLocation); SerializedProperty propPath = serializedObject.FindProperty("m_VideoPath"); EditorGUILayout.PropertyField(propPath); GUI.enabled = true; if (!Application.isPlaying) { GUILayout.BeginHorizontal(); OnInspectorGUI_RecentButton(propPath, propLocation); GUI.color = Color.green; if (GUILayout.Button("BROWSE")) { string startFolder = GetStartFolder(propPath.stringValue, (MediaPlayer.FileLocation)propLocation.enumValueIndex); string videoPath = media.m_VideoPath; string fullPath = string.Empty; MediaPlayer.FileLocation fileLocation = media.m_VideoLocation; if (Browse(startFolder, ref videoPath, ref fileLocation, ref fullPath)) { propPath.stringValue = videoPath; propLocation.enumValueIndex = (int)fileLocation; EditorUtility.SetDirty(target); AddToRecentFiles(fullPath); } } GUILayout.EndHorizontal(); ShowFileWarningMessages(propPath.stringValue, (MediaPlayer.FileLocation)propLocation.enumValueIndex, media.m_AutoOpen, Platform.Unknown); GUI.color = Color.white; } OnInspectorGUI_CopyableFilename(media.m_VideoPath); EditorGUILayout.EndVertical(); /////////////////// STARTUP FIELDS EditorGUILayout.BeginVertical("box"); GUILayout.Label("Startup", EditorStyles.boldLabel); SerializedProperty propAutoOpen = serializedObject.FindProperty("m_AutoOpen"); EditorGUILayout.PropertyField(propAutoOpen); SerializedProperty propAutoStart = serializedObject.FindProperty("m_AutoStart"); EditorGUILayout.PropertyField(propAutoStart); EditorGUILayout.EndVertical(); /////////////////// PLAYBACK FIELDS EditorGUILayout.BeginVertical("box"); GUILayout.Label("Playback", EditorStyles.boldLabel); if (!Application.isPlaying) { SerializedProperty propLoop = serializedObject.FindProperty("m_Loop"); EditorGUILayout.PropertyField(propLoop); SerializedProperty propVolume = serializedObject.FindProperty("m_Volume"); EditorGUILayout.PropertyField(propVolume); SerializedProperty propMuted = serializedObject.FindProperty("m_Muted"); EditorGUILayout.PropertyField(propMuted); } else { if (media.Control != null) { media.m_Loop = media.Control.IsLooping(); bool newLooping = EditorGUILayout.Toggle("Loop", media.m_Loop); if (newLooping != media.m_Loop) { media.Control.SetLooping(newLooping); } media.m_Volume = media.Control.GetVolume(); float newVolume = EditorGUILayout.Slider("Volume", media.m_Volume, 0f, 1f); if (newVolume != media.m_Volume) { media.Control.SetVolume(newVolume); } media.m_Muted = media.Control.IsMuted(); bool newMuted = EditorGUILayout.Toggle("Muted", media.m_Muted); if (newMuted != media.m_Muted) { media.Control.MuteAudio(newMuted); } } } SerializedProperty propDebugGui = serializedObject.FindProperty("m_DebugGui"); EditorGUILayout.PropertyField(propDebugGui); EditorGUILayout.EndVertical(); /////////////////// MEDIA PROPERTIES /*if (!Application.isPlaying) * { * OnInspectorGUI_MediaProperties(); * }*/ //////////////////// PREVIEW OnInspectorGUI_Preview(); /////////////////// EVENTS OnInspectorGUI_Events(); /////////////////// PLATFORM OVERRIDES if (!Application.isPlaying) { OnInspectorGUI_PlatformOverrides(); } if (serializedObject.ApplyModifiedProperties()) { EditorUtility.SetDirty(target); } if (!Application.isPlaying) { OnInspectorGUI_About(); } }
private static void GetRelativeLocationFromPath(string path, ref string filePath, ref MediaPlayer.FileLocation fileLocation) { string projectRoot = System.IO.Path.GetFullPath(System.IO.Path.Combine(Application.dataPath, "..")); projectRoot = projectRoot.Replace('\\', '/'); if (path.StartsWith(projectRoot)) { if (path.StartsWith(Application.streamingAssetsPath)) { // Must be StreamingAssets relative path filePath = GetPathRelativeTo(Application.streamingAssetsPath, path); fileLocation = MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder; } else if (path.StartsWith(Application.dataPath)) { // Must be Assets relative path filePath = GetPathRelativeTo(Application.dataPath, path); fileLocation = MediaPlayer.FileLocation.RelativeToDataFolder; } else { // Must be project relative path filePath = GetPathRelativeTo(projectRoot, path); fileLocation = MediaPlayer.FileLocation.RelativeToProjectFolder; } } else { // Must be persistant data if (path.StartsWith(Application.persistentDataPath)) { filePath = GetPathRelativeTo(Application.persistentDataPath, path); fileLocation = MediaPlayer.FileLocation.RelativeToPeristentDataFolder; } // Must be absolute path filePath = path; fileLocation = MediaPlayer.FileLocation.AbsolutePathOrURL; } }