Commit 1f82cfb41fbc298f3fdac12701de9e8086121bfd
1 parent
1cd22e49
Exists in
master
and in
3 other branches
Finish Handle Download
Showing
5 changed files
with
144 additions
and
108 deletions
Show diff stats
Assets/Scenes/Main.unity
| @@ -811,7 +811,7 @@ RectTransform: | @@ -811,7 +811,7 @@ RectTransform: | ||
| 811 | m_AnchorMin: {x: 0, y: 1.7} | 811 | m_AnchorMin: {x: 0, y: 1.7} |
| 812 | m_AnchorMax: {x: 0.97, y: 2.2} | 812 | m_AnchorMax: {x: 0.97, y: 2.2} |
| 813 | m_AnchoredPosition: {x: 0, y: 0} | 813 | m_AnchoredPosition: {x: 0, y: 0} |
| 814 | - m_SizeDelta: {x: 0, y: 0} | 814 | + m_SizeDelta: {x: -239.8714, y: 0} |
| 815 | m_Pivot: {x: 1, y: 0} | 815 | m_Pivot: {x: 1, y: 0} |
| 816 | --- !u!114 &160532053 | 816 | --- !u!114 &160532053 |
| 817 | MonoBehaviour: | 817 | MonoBehaviour: |
| @@ -3963,7 +3963,7 @@ RectTransform: | @@ -3963,7 +3963,7 @@ RectTransform: | ||
| 3963 | m_AnchorMin: {x: 0, y: 1.7} | 3963 | m_AnchorMin: {x: 0, y: 1.7} |
| 3964 | m_AnchorMax: {x: 0.97, y: 2.2} | 3964 | m_AnchorMax: {x: 0.97, y: 2.2} |
| 3965 | m_AnchoredPosition: {x: 0, y: 0} | 3965 | m_AnchoredPosition: {x: 0, y: 0} |
| 3966 | - m_SizeDelta: {x: 0, y: 0} | 3966 | + m_SizeDelta: {x: -239.8714, y: 0} |
| 3967 | m_Pivot: {x: 1, y: 0} | 3967 | m_Pivot: {x: 1, y: 0} |
| 3968 | --- !u!114 &581668678 | 3968 | --- !u!114 &581668678 |
| 3969 | MonoBehaviour: | 3969 | MonoBehaviour: |
| @@ -7238,13 +7238,12 @@ RectTransform: | @@ -7238,13 +7238,12 @@ RectTransform: | ||
| 7238 | m_AnchorMin: {x: 0, y: 1.7} | 7238 | m_AnchorMin: {x: 0, y: 1.7} |
| 7239 | m_AnchorMax: {x: 0.97, y: 2.2} | 7239 | m_AnchorMax: {x: 0.97, y: 2.2} |
| 7240 | m_AnchoredPosition: {x: 0, y: 0} | 7240 | m_AnchoredPosition: {x: 0, y: 0} |
| 7241 | - m_SizeDelta: {x: 0, y: 0} | 7241 | + m_SizeDelta: {x: -239.8714, y: 0} |
| 7242 | m_Pivot: {x: 1, y: 0} | 7242 | m_Pivot: {x: 1, y: 0} |
| 7243 | --- !u!114 &1059619784 | 7243 | --- !u!114 &1059619784 |
| 7244 | MonoBehaviour: | 7244 | MonoBehaviour: |
| 7245 | m_ObjectHideFlags: 0 | 7245 | m_ObjectHideFlags: 0 |
| 7246 | - m_PrefabParentObject: {fileID: 11431640, guid: 5ccb0ba277304a14b9bb8d4e34161675, | ||
| 7247 | - type: 2} | 7246 | + m_PrefabParentObject: {fileID: 0} |
| 7248 | m_PrefabInternal: {fileID: 0} | 7247 | m_PrefabInternal: {fileID: 0} |
| 7249 | m_GameObject: {fileID: 1059619782} | 7248 | m_GameObject: {fileID: 1059619782} |
| 7250 | m_Enabled: 1 | 7249 | m_Enabled: 1 |
| @@ -7253,7 +7252,7 @@ MonoBehaviour: | @@ -7253,7 +7252,7 @@ MonoBehaviour: | ||
| 7253 | m_Name: | 7252 | m_Name: |
| 7254 | m_EditorClassIdentifier: | 7253 | m_EditorClassIdentifier: |
| 7255 | m_Navigation: | 7254 | m_Navigation: |
| 7256 | - m_Mode: 0 | 7255 | + m_Mode: 3 |
| 7257 | m_SelectOnUp: {fileID: 0} | 7256 | m_SelectOnUp: {fileID: 0} |
| 7258 | m_SelectOnDown: {fileID: 0} | 7257 | m_SelectOnDown: {fileID: 0} |
| 7259 | m_SelectOnLeft: {fileID: 0} | 7258 | m_SelectOnLeft: {fileID: 0} |
Assets/Scripts/Export Video/ExportLayers.cs
| @@ -11,6 +11,7 @@ public class ExportLayers{ | @@ -11,6 +11,7 @@ public class ExportLayers{ | ||
| 11 | Share_Layer, | 11 | Share_Layer, |
| 12 | Progress_Download_Layer, | 12 | Progress_Download_Layer, |
| 13 | OnLockExport, | 13 | OnLockExport, |
| 14 | + OnLockShare, | ||
| 14 | All | 15 | All |
| 15 | } | 16 | } |
| 16 | 17 | ||
| @@ -19,6 +20,7 @@ public class ExportLayers{ | @@ -19,6 +20,7 @@ public class ExportLayers{ | ||
| 19 | INTERNET_CONNECTION_FAILURE, | 20 | INTERNET_CONNECTION_FAILURE, |
| 20 | DOWNLOAD_CONNECTION_FAILURE, | 21 | DOWNLOAD_CONNECTION_FAILURE, |
| 21 | CONNECTION_TIMEOUT_FAILURE, | 22 | CONNECTION_TIMEOUT_FAILURE, |
| 22 | - ERROR_CONNECTION_FAILURE | 23 | + ERROR_CONNECTION_FAILURE, |
| 24 | + DEFAULT | ||
| 23 | } | 25 | } |
| 24 | } | 26 | } |
Assets/Scripts/Export Video/ExportVideo.cs
| @@ -34,14 +34,9 @@ public class ExportVideo : MonoBehaviour { | @@ -34,14 +34,9 @@ public class ExportVideo : MonoBehaviour { | ||
| 34 | 34 | ||
| 35 | private const string SERVER_URL = "http://150.165.205.57/video/"; | 35 | private const string SERVER_URL = "http://150.165.205.57/video/"; |
| 36 | 36 | ||
| 37 | - /*Strings to Compare glosses*/ | ||
| 38 | - private static string gloss = "Gloss"; | ||
| 39 | - private string currentGloss = "CurrentGloss"; | ||
| 40 | - | ||
| 41 | - /* Sharing Current Time - Video Name*/ | ||
| 42 | - private string currentTime = ""; | ||
| 43 | - | ||
| 44 | 37 | ||
| 38 | + private static string gloss = "Gloss"; | ||
| 39 | + | ||
| 45 | 40 | ||
| 46 | /* Strings related to the Android Dialog*/ | 41 | /* Strings related to the Android Dialog*/ |
| 47 | private string title = "Download"; | 42 | private string title = "Download"; |
| @@ -101,15 +96,12 @@ public class ExportVideo : MonoBehaviour { | @@ -101,15 +96,12 @@ public class ExportVideo : MonoBehaviour { | ||
| 101 | 96 | ||
| 102 | public void onDownloadClick() | 97 | public void onDownloadClick() |
| 103 | { | 98 | { |
| 104 | - MobileNativeDialog nativeDialog; | ||
| 105 | - | ||
| 106 | - | 99 | + MobileNativeDialog nativeDialog; |
| 107 | 100 | ||
| 108 | nativeDialog = new MobileNativeDialog(title, message + ((videoSize/1024f)/1024f).ToString("0.00") + " MB.", yesOp, noOp); | 101 | nativeDialog = new MobileNativeDialog(title, message + ((videoSize/1024f)/1024f).ToString("0.00") + " MB.", yesOp, noOp); |
| 109 | nativeDialog.OnComplete = OnComplete; | 102 | nativeDialog.OnComplete = OnComplete; |
| 110 | 103 | ||
| 111 | - } | ||
| 112 | - | 104 | + } |
| 113 | 105 | ||
| 114 | /** Delegate function which waits for YES or NO from the MobileDialog | 106 | /** Delegate function which waits for YES or NO from the MobileDialog |
| 115 | * and attach a action to each option**/ | 107 | * and attach a action to each option**/ |
| @@ -165,33 +157,19 @@ public class ExportVideo : MonoBehaviour { | @@ -165,33 +157,19 @@ public class ExportVideo : MonoBehaviour { | ||
| 165 | 157 | ||
| 166 | public void OnShareVideo() | 158 | public void OnShareVideo() |
| 167 | { | 159 | { |
| 168 | - PlayerLogger.Log("ExportVideo", "OnShareVideo", "Sharing Video..."); | ||
| 169 | - | ||
| 170 | - if (gloss == currentGloss) //Checking if user is trying to share the same animation | ||
| 171 | - { | ||
| 172 | - Share(); | ||
| 173 | - } | ||
| 174 | - else | ||
| 175 | - { | ||
| 176 | - currentGloss = gloss; | ||
| 177 | - currentTime = System.DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss"); | ||
| 178 | - Share(); | ||
| 179 | - } | ||
| 180 | - } | ||
| 181 | - | ||
| 182 | - private void Share() | ||
| 183 | - { | ||
| 184 | 160 | ||
| 185 | try | 161 | try |
| 186 | { | 162 | { |
| 187 | if (videoContent != null) | 163 | if (videoContent != null) |
| 188 | { | 164 | { |
| 165 | + Action errorAction = () => { screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); | ||
| 166 | + new AndroidToast().showToast("Erro ao compartilhar mídia."); }; | ||
| 189 | 167 | ||
| 190 | - MediaShareAndroid.ShareActivity(videoContent, bytes, currentTime); | 168 | + StartCoroutine(MediaShareAndroid.ShareIntent(errorAction)); |
| 191 | } | 169 | } |
| 192 | else | 170 | else |
| 193 | { | 171 | { |
| 194 | - new AndroidToast().showToast("Erro ao compartilhar vídeo"); | 172 | + new AndroidToast().showToast("Erro ao compartilhar mídia."); |
| 195 | screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); | 173 | screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); |
| 196 | } | 174 | } |
| 197 | } | 175 | } |
| @@ -235,24 +213,25 @@ public class ExportVideo : MonoBehaviour { | @@ -235,24 +213,25 @@ public class ExportVideo : MonoBehaviour { | ||
| 235 | } | 213 | } |
| 236 | else if (videoInfoRequest.responseHeaders.Count == 0) | 214 | else if (videoInfoRequest.responseHeaders.Count == 0) |
| 237 | { | 215 | { |
| 216 | + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); | ||
| 238 | PlayerLogger.Log("ExportVideo", "requestVideoInfo", "(WWW) Unsucessful Answer"); | 217 | PlayerLogger.Log("ExportVideo", "requestVideoInfo", "(WWW) Unsucessful Answer"); |
| 239 | GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); | 218 | GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); |
| 240 | - screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); | 219 | + |
| 241 | 220 | ||
| 242 | } | 221 | } |
| 243 | else if (!videoInfoRequest.responseHeaders["STATUS"].Contains("200")) | 222 | else if (!videoInfoRequest.responseHeaders["STATUS"].Contains("200")) |
| 244 | { | 223 | { |
| 245 | - | 224 | + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); |
| 246 | PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Unsuccessful answer (" + videoInfoRequest.responseHeaders["STATUS"] + ")."); | 225 | PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Unsuccessful answer (" + videoInfoRequest.responseHeaders["STATUS"] + ")."); |
| 247 | GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); | 226 | GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); |
| 248 | - screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); | 227 | + |
| 249 | 228 | ||
| 250 | } | 229 | } |
| 251 | else if (String.IsNullOrEmpty(videoInfoRequest.text)) | 230 | else if (String.IsNullOrEmpty(videoInfoRequest.text)) |
| 252 | { | 231 | { |
| 253 | 232 | ||
| 254 | screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); | 233 | screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); |
| 255 | - GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); | 234 | + GetConnectionStatusError(ExportLayers.ConnectionStatusError.DEFAULT); |
| 256 | PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Empty answer."); | 235 | PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Empty answer."); |
| 257 | } | 236 | } |
| 258 | else | 237 | else |
| @@ -285,24 +264,49 @@ public class ExportVideo : MonoBehaviour { | @@ -285,24 +264,49 @@ public class ExportVideo : MonoBehaviour { | ||
| 285 | { | 264 | { |
| 286 | videoDownloadRunning = true; | 265 | videoDownloadRunning = true; |
| 287 | WWW DownloadVideo = new WWW(SERVER_URL + videoId); | 266 | WWW DownloadVideo = new WWW(SERVER_URL + videoId); |
| 288 | - // WWW DownloadVideo = new WWW("http://caiomcg.com/rural.mp4"); | 267 | + |
| 289 | while (!DownloadVideo.isDone) | 268 | while (!DownloadVideo.isDone) |
| 290 | { | 269 | { |
| 291 | screenManager.updateProgressDownloadSprite(DownloadVideo.progress); | 270 | screenManager.updateProgressDownloadSprite(DownloadVideo.progress); |
| 271 | + | ||
| 292 | yield return null; | 272 | yield return null; |
| 293 | } | 273 | } |
| 294 | 274 | ||
| 295 | try | 275 | try |
| 296 | { | 276 | { |
| 297 | - if (DownloadVideo.bytesDownloaded > 0 && DownloadVideo.bytesDownloaded<=videoSize) | 277 | + |
| 278 | + if(DownloadVideo.error != null) | ||
| 279 | + { | ||
| 280 | + GetConnectionStatusError(ExportLayers.ConnectionStatusError.INTERNET_CONNECTION_FAILURE); | ||
| 281 | + ErrorDownloading(); | ||
| 282 | + | ||
| 283 | + } | ||
| 284 | + else if(DownloadVideo.responseHeaders.Count == 0) | ||
| 285 | + { | ||
| 286 | + GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); | ||
| 287 | + ErrorDownloading(); | ||
| 288 | + | ||
| 289 | + } | ||
| 290 | + else if (!DownloadVideo.responseHeaders["STATUS"].Contains("200")) | ||
| 291 | + { | ||
| 292 | + GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); | ||
| 293 | + ErrorDownloading(); | ||
| 294 | + | ||
| 295 | + } | ||
| 296 | + else if ( DownloadVideo.bytesDownloaded == videoSize) | ||
| 298 | { | 297 | { |
| 299 | bytes = DownloadVideo.bytesDownloaded; | 298 | bytes = DownloadVideo.bytesDownloaded; |
| 300 | videoContent = DownloadVideo.bytes; | 299 | videoContent = DownloadVideo.bytes; |
| 301 | - OnDownloadFinished(); | 300 | + Action callBack = () => { OnDownloadFinished(); new AndroidToast().showToast("Vídeo salvo na Galeria."); }; |
| 301 | + Action errorWriting = () => { screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); }; | ||
| 302 | + videoDownloadRunning = false; | ||
| 303 | + StartCoroutine(MediaShareAndroid.WriteOnAndroid(videoContent, bytes, System.DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss"),callBack,errorWriting)); | ||
| 304 | + | ||
| 302 | } | 305 | } |
| 303 | else | 306 | else |
| 304 | { | 307 | { |
| 305 | GetConnectionStatusError(ExportLayers.ConnectionStatusError.DOWNLOAD_CONNECTION_FAILURE); | 308 | GetConnectionStatusError(ExportLayers.ConnectionStatusError.DOWNLOAD_CONNECTION_FAILURE); |
| 309 | + ErrorDownloading(); | ||
| 306 | } | 310 | } |
| 307 | 311 | ||
| 308 | 312 | ||
| @@ -313,6 +317,16 @@ public class ExportVideo : MonoBehaviour { | @@ -313,6 +317,16 @@ public class ExportVideo : MonoBehaviour { | ||
| 313 | } | 317 | } |
| 314 | } | 318 | } |
| 315 | 319 | ||
| 320 | + /* In case of error during the video download, the user gets a new chance to download the file, but | ||
| 321 | + * is also able to start a new fresh animation and export it */ | ||
| 322 | + private void ErrorDownloading() | ||
| 323 | + { | ||
| 324 | + screenManager.changeExportStates(ExportLayers.ExportLayer.Progress_Download_Layer, false); | ||
| 325 | + screenManager.changeExportStates(ExportLayers.ExportLayer.Download_Layer, true); | ||
| 326 | + screenManager.changeExportStates(ExportLayers.ExportLayer.OnLockExport, false); | ||
| 327 | + screenManager.changeExportStates(ExportLayers.ExportLayer.OnLockShare, false); | ||
| 328 | + } | ||
| 329 | + | ||
| 316 | public IEnumerator WaitForResponse(WWW www, Events.RequestSuccess success, Events.RequestError error) | 330 | public IEnumerator WaitForResponse(WWW www, Events.RequestSuccess success, Events.RequestError error) |
| 317 | { | 331 | { |
| 318 | yield return Methods.WaitForResponse(www, 60*5f, success, error); | 332 | yield return Methods.WaitForResponse(www, 60*5f, success, error); |
| @@ -324,6 +338,7 @@ public class ExportVideo : MonoBehaviour { | @@ -324,6 +338,7 @@ public class ExportVideo : MonoBehaviour { | ||
| 324 | yield return WaitForResponse(www, null, null); | 338 | yield return WaitForResponse(www, null, null); |
| 325 | } | 339 | } |
| 326 | 340 | ||
| 341 | + /* Error states to show a Toast to user*/ | ||
| 327 | private static void GetConnectionStatusError(ExportLayers.ConnectionStatusError error) | 342 | private static void GetConnectionStatusError(ExportLayers.ConnectionStatusError error) |
| 328 | { | 343 | { |
| 329 | switch (error) | 344 | switch (error) |
Assets/Scripts/Export Video/MediaShareAndroid.cs
| @@ -18,6 +18,7 @@ using UnityEngine; | @@ -18,6 +18,7 @@ using UnityEngine; | ||
| 18 | using System.Collections; | 18 | using System.Collections; |
| 19 | using System.IO; | 19 | using System.IO; |
| 20 | using System; | 20 | using System; |
| 21 | +using LAViD.Unity.Utils; | ||
| 21 | 22 | ||
| 22 | 23 | ||
| 23 | 24 | ||
| @@ -30,9 +31,10 @@ public class MediaShareAndroid : MonoBehaviour | @@ -30,9 +31,10 @@ public class MediaShareAndroid : MonoBehaviour | ||
| 30 | 31 | ||
| 31 | private string AndroidPath; | 32 | private string AndroidPath; |
| 32 | 33 | ||
| 33 | - private string destination = ""; | 34 | + private static string destination = ""; |
| 34 | private string Vlibras = "DCIM/VLibras"; | 35 | private string Vlibras = "DCIM/VLibras"; |
| 35 | - private string File = "VLibrasVideo_"; | 36 | + private string Filen = "VLibrasVideo_"; |
| 37 | + private static string FilePath = ""; | ||
| 36 | 38 | ||
| 37 | private byte[] videoContent; | 39 | private byte[] videoContent; |
| 38 | private int bytes; | 40 | private int bytes; |
| @@ -45,25 +47,12 @@ public class MediaShareAndroid : MonoBehaviour | @@ -45,25 +47,12 @@ public class MediaShareAndroid : MonoBehaviour | ||
| 45 | 47 | ||
| 46 | /*Makes sure that Vlibras Folder gets created and write the video bytes in it.*/ | 48 | /*Makes sure that Vlibras Folder gets created and write the video bytes in it.*/ |
| 47 | 49 | ||
| 48 | - /* Creates the sharing activity and shows the chooser to the user*/ | ||
| 49 | - | ||
| 50 | - public void ShareActivity(byte[] videoContent,int bytes, string CurrentTime) | 50 | + public IEnumerator WriteOnAndroid(byte[] videoContent, int bytes,string CurrentTime, Action finishWriting, Action errorWriting) |
| 51 | { | 51 | { |
| 52 | - | ||
| 53 | #if UNITY_ANDROID | 52 | #if UNITY_ANDROID |
| 54 | - | ||
| 55 | - this.videoContent = videoContent; | ||
| 56 | - this.bytes = bytes; | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - StartCoroutine(WriteOnAndroid(File + CurrentTime + ".mp4")); | ||
| 60 | - | ||
| 61 | -#endif | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - private IEnumerator WriteOnAndroid(string FileName) | ||
| 65 | - { | 53 | + FilePath = Filen + CurrentTime + ".mp4"; |
| 66 | destination = Path.Combine(AndroidPath, Vlibras); | 54 | destination = Path.Combine(AndroidPath, Vlibras); |
| 55 | + | ||
| 67 | 56 | ||
| 68 | /* Checking if folder Vlibras exists*/ | 57 | /* Checking if folder Vlibras exists*/ |
| 69 | 58 | ||
| @@ -72,72 +61,98 @@ public class MediaShareAndroid : MonoBehaviour | @@ -72,72 +61,98 @@ public class MediaShareAndroid : MonoBehaviour | ||
| 72 | { | 61 | { |
| 73 | dir.Create(); | 62 | dir.Create(); |
| 74 | } | 63 | } |
| 75 | - | ||
| 76 | - /*Checking if there's a file with same name - If so, means user's trying | ||
| 77 | - * to share the same video*/ | ||
| 78 | - | ||
| 79 | - dir = new DirectoryInfo(Path.Combine(destination, FileName)); | ||
| 80 | - if (!dir.Exists) | 64 | + |
| 65 | + try | ||
| 66 | + { | ||
| 67 | + FileStream SourceStream = new FileStream(Path.Combine(destination, FilePath), FileMode.OpenOrCreate); | ||
| 68 | + if (SourceStream.CanWrite) | ||
| 69 | + { | ||
| 70 | + SourceStream.Write(videoContent, 0, bytes); | ||
| 71 | + SourceStream.Close(); | ||
| 72 | + | ||
| 73 | + Refresh(FilePath); | ||
| 74 | + finishWriting(); | ||
| 75 | + yield break; | ||
| 76 | + | ||
| 77 | + } | ||
| 78 | + else | ||
| 79 | + { | ||
| 80 | + new AndroidToast().showToast("Erro ao salvar vídeo."); | ||
| 81 | + errorWriting(); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + | ||
| 85 | + } | ||
| 86 | + catch (Exception e) | ||
| 81 | { | 87 | { |
| 82 | - FileStream SourceStream = new FileStream(Path.Combine(destination, FileName), FileMode.OpenOrCreate); | ||
| 83 | - if (SourceStream.CanWrite) | ||
| 84 | - { | ||
| 85 | - SourceStream.Write(videoContent, 0, bytes); | ||
| 86 | - SourceStream.Close(); | ||
| 87 | - | ||
| 88 | - } | ||
| 89 | - else | ||
| 90 | - { | ||
| 91 | - new AndroidToast().showToast("Erro ao compartilhar arquivo."); | ||
| 92 | - } | ||
| 93 | - | 88 | + PlayerLogger.Log("MediaShareAndroid", "WriteOnAndroid","Message: " + e.Message); |
| 89 | + PlayerLogger.Log("MediaShareAndroid", "WriteOnAndroid", "Message: " + e.StackTrace); | ||
| 90 | + new AndroidToast().showToast("Você precisa dá permissão ao aplicativo"); | ||
| 91 | + errorWriting(); | ||
| 94 | } | 92 | } |
| 95 | 93 | ||
| 96 | - yield return null; | ||
| 97 | - Refresh(FileName); | ||
| 98 | 94 | ||
| 95 | + | ||
| 96 | +#endif | ||
| 97 | + | ||
| 99 | 98 | ||
| 100 | 99 | ||
| 101 | 100 | ||
| 102 | } | 101 | } |
| 103 | 102 | ||
| 104 | - private void Refresh(string FileName) | ||
| 105 | - { | 103 | + /* Calling Android Services to refresh the video path, making available to show in gallery*/ |
| 106 | 104 | ||
| 105 | + private void Refresh(string FilePath) | ||
| 106 | + { | ||
| 107 | + | ||
| 107 | AndroidJavaClass jcUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); | 108 | AndroidJavaClass jcUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| 108 | AndroidJavaObject joActivity = jcUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); | 109 | AndroidJavaObject joActivity = jcUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); |
| 109 | AndroidJavaObject joContext = joActivity.Call<AndroidJavaObject>("getApplicationContext"); | 110 | AndroidJavaObject joContext = joActivity.Call<AndroidJavaObject>("getApplicationContext"); |
| 110 | AndroidJavaClass jcMediaScannerConnection = new AndroidJavaClass("android.media.MediaScannerConnection"); | 111 | AndroidJavaClass jcMediaScannerConnection = new AndroidJavaClass("android.media.MediaScannerConnection"); |
| 111 | - //AndroidJavaClass jcEnvironment = new AndroidJavaClass("android.os.Environment"); | ||
| 112 | - // AndroidJavaObject joExDir = jcEnvironment.CallStatic<AndroidJavaObject>("getExternalStorageDirectory"); | ||
| 113 | - string path = Path.Combine(destination,FileName); | ||
| 114 | - jcMediaScannerConnection.CallStatic("scanFile", joContext, new string[] { path }, null, null); | ||
| 115 | - StartCoroutine(ShareIntent(FileName)); | 112 | + //AndroidJavaClass jcEnvironment = new AndroidJavaClass("android.os.Environment"); |
| 113 | + // AndroidJavaObject joExDir = jcEnvironment.CallStatic<AndroidJavaObject>("getExternalStorageDirectory"); | ||
| 114 | + string path = destination; | ||
| 115 | + jcMediaScannerConnection.CallStatic("scanFile", joContext, new string[] { path }, new string[] { "video/mp4" },null ); | ||
| 116 | + | ||
| 117 | + | ||
| 116 | 118 | ||
| 117 | } | 119 | } |
| 118 | 120 | ||
| 119 | - private IEnumerator ShareIntent(string FileName) { | ||
| 120 | 121 | ||
| 121 | - // block to open the file and share it ------------START | ||
| 122 | - AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent"); | ||
| 123 | - AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent"); | ||
| 124 | - intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND")); | 122 | + /* Calling Android Services to create Share Intent*/ |
| 125 | 123 | ||
| 126 | - AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"); | ||
| 127 | - AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + Path.Combine(destination,FileName)); | ||
| 128 | - | ||
| 129 | - intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject); | ||
| 130 | - intentObject.Call<AndroidJavaObject>("setType", MediaType); | 124 | + public IEnumerator ShareIntent(Action errorAction) { |
| 125 | + | ||
| 126 | + | ||
| 127 | + if(File.Exists(Path.Combine(destination, FilePath))) | ||
| 128 | + { | ||
| 131 | 129 | ||
| 132 | - //add data to be passed to the other activity i.e., the data to be sent | ||
| 133 | - intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), "VLibras"); | ||
| 134 | - intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), SubtitleMessage); | ||
| 135 | - intentObject.Call<AndroidJavaObject>("setType", "video/*"); | ||
| 136 | - AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); | ||
| 137 | - AndroidJavaObject jChooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, "Compartilhar via"); | ||
| 138 | - AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity"); | ||
| 139 | - currentActivity.Call("startActivity", jChooser); | ||
| 140 | - yield break; | 130 | + // block to open the file and share it ------------START |
| 131 | + AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent"); | ||
| 132 | + AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent"); | ||
| 133 | + intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND")); | ||
| 134 | + | ||
| 135 | + AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"); | ||
| 136 | + AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + Path.Combine(destination, FilePath)); | ||
| 137 | + | ||
| 138 | + intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject); | ||
| 139 | + intentObject.Call<AndroidJavaObject>("setType", MediaType); | ||
| 140 | + | ||
| 141 | + //add data to be passed to the other activity i.e., the data to be sent | ||
| 142 | + intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), "VLibras"); | ||
| 143 | + intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), SubtitleMessage); | ||
| 144 | + intentObject.Call<AndroidJavaObject>("setType", "video/*"); | ||
| 145 | + AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); | ||
| 146 | + AndroidJavaObject jChooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, "Compartilhar via"); | ||
| 147 | + AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity"); | ||
| 148 | + currentActivity.Call("startActivity", jChooser); | ||
| 149 | + yield break; | ||
| 150 | + }else | ||
| 151 | + { | ||
| 152 | + errorAction(); | ||
| 153 | + | ||
| 154 | + yield break; | ||
| 155 | + } | ||
| 141 | 156 | ||
| 142 | 157 | ||
| 143 | } | 158 | } |
Assets/Scripts/UI/ScreenManager.cs
| @@ -317,6 +317,8 @@ public class ScreenManager : MonoBehaviour { | @@ -317,6 +317,8 @@ public class ScreenManager : MonoBehaviour { | ||
| 317 | this.shareLayer.SetActive(active); | 317 | this.shareLayer.SetActive(active); |
| 318 | } | 318 | } |
| 319 | 319 | ||
| 320 | + | ||
| 321 | + | ||
| 320 | public void setTranslateButtonActive(bool active) | 322 | public void setTranslateButtonActive(bool active) |
| 321 | { | 323 | { |
| 322 | this.textButton.SetActive(active); | 324 | this.textButton.SetActive(active); |
| @@ -379,6 +381,9 @@ public class ScreenManager : MonoBehaviour { | @@ -379,6 +381,9 @@ public class ScreenManager : MonoBehaviour { | ||
| 379 | case ExportLayers.ExportLayer.OnLockExport: | 381 | case ExportLayers.ExportLayer.OnLockExport: |
| 380 | onLockExport = show_Layer; | 382 | onLockExport = show_Layer; |
| 381 | break; | 383 | break; |
| 384 | + case ExportLayers.ExportLayer.OnLockShare: | ||
| 385 | + onLockShare = show_Layer; | ||
| 386 | + break; | ||
| 382 | default: | 387 | default: |
| 383 | onLockShare = false; | 388 | onLockShare = false; |
| 384 | onLockExport = false; | 389 | onLockExport = false; |