Commit 73e36320e7d418f8054154dc6ee67ad996b286a8

Authored by Thiago Filipe Soares da Rocha
1 parent 2f0622dd

Share Video Issue

Assets/Plugins/Android/AndroidManifest.xml
... ... @@ -24,6 +24,6 @@
24 24 <category android:name="android.intent.category.LAUNCHER" />
25 25 </intent-filter>
26 26 <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
27   - </activity>
  27 + </activity>
28 28 </application>
29 29 </manifest>
30 30 \ No newline at end of file
... ...
Assets/Plugins/Android/file_paths.xml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<paths>
  3 + <external-path path="Android/data/com.lavid.vlibras/" name="files_root" />
  4 + <external-path path="." name="external_storage_root" />
  5 +</paths>
0 6 \ No newline at end of file
... ...
Assets/Plugins/Android/file_paths.xml.meta 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +fileFormatVersion: 2
  2 +guid: 3efe7884117ce2a42ab53ef3041426fc
  3 +timeCreated: 1486638270
  4 +licenseType: Free
  5 +TextScriptImporter:
  6 + userData:
  7 + assetBundleName:
  8 + assetBundleVariant:
... ...
Assets/Scenes/Main.unity
... ... @@ -793,7 +793,7 @@ GameObject:
793 793 m_Icon: {fileID: 0}
794 794 m_NavMeshLayer: 0
795 795 m_StaticEditorFlags: 0
796   - m_IsActive: 0
  796 + m_IsActive: 1
797 797 --- !u!224 &160532052
798 798 RectTransform:
799 799 m_ObjectHideFlags: 0
... ...
Assets/Scripts/Export Video/AndroidPath.cs 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +using UnityEngine;
  2 +using System.Collections;
  3 +using System;
  4 +
  5 +
  6 +public class AndroidPaths : MonoBehaviour {
  7 +
  8 + public static string GetAndroidContextExternalFilesDir
  9 + {
  10 + get
  11 + {
  12 + string path = "";
  13 +
  14 + if (Application.platform == RuntimePlatform.Android)
  15 + {
  16 + try
  17 + {
  18 + using (AndroidJavaClass ajc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  19 + {
  20 + using (AndroidJavaObject ajo = ajc.GetStatic<AndroidJavaObject>("currentActivity"))
  21 + {
  22 + path = ajo.Call<AndroidJavaObject>("getExternalFilesDir", null).Call<string>("getAbsolutePath");
  23 + }
  24 + }
  25 + }
  26 + catch (Exception e)
  27 + {
  28 + Debug.LogWarning("Error fetching native Android external storage dir: " + e.Message);
  29 + }
  30 + }
  31 + return path;
  32 + }
  33 + }
  34 +
  35 + public static string GetAndroidContextInternalFilesDir
  36 + {
  37 + get
  38 + {
  39 + string path = "";
  40 +
  41 + if (Application.platform == RuntimePlatform.Android)
  42 + {
  43 + try
  44 + {
  45 + using (AndroidJavaClass ajc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  46 + {
  47 + using (AndroidJavaObject ajo = ajc.GetStatic<AndroidJavaObject>("currentActivity"))
  48 + {
  49 + path = ajo.Call<AndroidJavaObject>("getFilesDir").Call<string>("getAbsolutePath");
  50 + }
  51 + }
  52 + }
  53 + catch (Exception e)
  54 + {
  55 + Debug.LogWarning("Error fetching native Android internal storage dir: " + e.Message);
  56 + }
  57 + }
  58 + return path;
  59 + }
  60 + }
  61 +
  62 +
  63 +}
... ...
Assets/Scripts/Export Video/AndroidPath.cs.meta 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +fileFormatVersion: 2
  2 +guid: 71dacb9b6a7d04349b9913751ef87ad4
  3 +timeCreated: 1486607668
  4 +licenseType: Free
  5 +MonoImporter:
  6 + serializedVersion: 2
  7 + defaultReferences: []
  8 + executionOrder: 0
  9 + icon: {instanceID: 0}
  10 + userData:
  11 + assetBundleName:
  12 + assetBundleVariant:
... ...
Assets/Scripts/Export Video/ExportVideo.cs
... ... @@ -45,6 +45,7 @@ public class ExportVideo : MonoBehaviour {
45 45  
46 46  
47 47 private float videoSize = 0;
  48 + private int bytes = 0;
48 49 private string videoId = "";
49 50 private byte[] videoContent = null;
50 51  
... ... @@ -157,21 +158,31 @@ public class ExportVideo : MonoBehaviour {
157 158 Debug.Log("Sharing video content");
158 159 if(gloss == currentGloss)
159 160 {
160   - if (videoContent != null)
161   - new MediaShareAndroid().ShareActivity(videoContent,currentTime);
162   - else
  161 + try
163 162 {
164   - new AndroidToast().showToast("Erro ao compartilhar vídeo");
165   - screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);
  163 + if (videoContent != null)
  164 + new MediaShareAndroid().ShareActivity(videoContent,bytes, currentTime);
  165 + else
  166 + {
  167 + new AndroidToast().showToast("Erro ao compartilhar vídeo");
  168 + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);
  169 + }
  170 + }
  171 + catch (Exception e)
  172 + {
  173 + new AndroidToast().showToast(e.Message);
  174 + new AndroidToast().showToast(e.StackTrace);
166 175 }
167 176  
168   - }else
  177 +
  178 + }
  179 + else
169 180 {
170 181 currentGloss = gloss;
171 182 currentTime = System.DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss");
172 183  
173 184 if (videoContent != null)
174   - new MediaShareAndroid().ShareActivity(videoContent, currentTime);
  185 + new MediaShareAndroid().ShareActivity(videoContent,bytes, currentTime);
175 186 else
176 187 {
177 188 screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);
... ... @@ -187,7 +198,8 @@ public class ExportVideo : MonoBehaviour {
187 198 private IEnumerator videoDownload()
188 199 {
189 200 videoDownloadRunning = true;
190   - WWW DownloadVideo = new WWW(SERVER_URL + videoId);
  201 + // WWW DownloadVideo = new WWW(SERVER_URL + videoId);
  202 + WWW DownloadVideo = new WWW("http://caiomcg.com/rural.mp4");
191 203 while (!DownloadVideo.isDone)
192 204 {
193 205 screenManager.updateProgressDownloadSprite(DownloadVideo.progress);
... ... @@ -196,8 +208,9 @@ public class ExportVideo : MonoBehaviour {
196 208  
197 209 try
198 210 {
199   - if (DownloadVideo.bytesDownloaded > 0 && DownloadVideo.bytesDownloaded <= videoSize)
  211 + if (DownloadVideo.bytesDownloaded > 0 )
200 212 {
  213 + bytes = DownloadVideo.bytesDownloaded;
201 214 videoContent = DownloadVideo.bytes;
202 215 OnDownloadFinished();
203 216 }
... ... @@ -293,7 +306,7 @@ public class ExportVideo : MonoBehaviour {
293 306  
294 307 public IEnumerator WaitForResponse(WWW www, Events.RequestSuccess success, Events.RequestError error)
295 308 {
296   - yield return Methods.WaitForResponse(www, 60f, success, error);
  309 + yield return Methods.WaitForResponse(www, 60*5f, success, error);
297 310  
298 311 }
299 312  
... ...
Assets/Scripts/Export Video/MediaShareAndroid.cs
... ... @@ -17,6 +17,7 @@
17 17 using UnityEngine;
18 18 using System.Collections;
19 19 using System.IO;
  20 +using System;
20 21  
21 22  
22 23  
... ... @@ -24,37 +25,32 @@ public class MediaShareAndroid : MonoBehaviour
24 25 {
25 26  
26 27 private string MediaType = "video/*";
27   - private string TitleMessage = "Compartilhar Vídeo";
  28 +
28 29 private string SubtitleMessage = "VLibras";
29 30  
30 31 private string AndroidPath = AndroidJavaUti.CurrentSDCardPath;
31   - private string Vlibras = "/VLibras";
32   - private string FileName = "/VLibrasVideo_";
33   -
34   -
35   - /*Makes sure that Vlibras Folder gets created and write the video bytes in it.*/
36   -
37   - private void WriteOnAndroid(byte[] videoContent)
38   - {
39   - if(!Directory.Exists(AndroidPath + Vlibras))
40   - {
41   - Directory.CreateDirectory(AndroidPath + Vlibras);
42   - }
43   - if (!Directory.Exists(AndroidPath + Vlibras + FileName))
44   - File.WriteAllBytes(AndroidPath + Vlibras + FileName, videoContent);
  32 +
  33 + private string destination = "";
  34 + private string Vlibras = "VLibras";
  35 + private string FileName = "VLibrasVideo_";
45 36  
  37 + private byte[] videoContent;
  38 + private int bytes;
46 39  
47 40  
48   - }
  41 + /*Makes sure that Vlibras Folder gets created and write the video bytes in it.*/
49 42  
50 43 /* Creates the sharing activity and shows the chooser to the user*/
51 44  
52   - public void ShareActivity(byte[] videoContent, string CurrentTime)
  45 + public void ShareActivity(byte[] videoContent,int bytes, string CurrentTime)
53 46 {
54 47  
55 48 #if UNITY_ANDROID
  49 + this.videoContent = videoContent;
  50 + this.bytes = bytes;
56 51 FileName += CurrentTime + ".mp4";
57   - WriteOnAndroid(videoContent);
  52 + ShareIntent();
  53 + /*
58 54 // Create Refernece of AndroidJavaClass class for intent
59 55 AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
60 56 // Create Refernece of AndroidJavaObject class intent
... ... @@ -67,18 +63,18 @@ public class MediaShareAndroid : MonoBehaviour
67 63 //Set title of action or intent
68 64 intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TITLE"), TitleMessage);
69 65  
70   - /*
  66 + /*
71 67 // Set actual data which you want to share
72 68 intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), Media);
73 69 AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
74 70 AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
75 71 // Invoke android activity for passing intent to share data
76 72 currentActivity.Call("startActivity", intentObject);
77   - */
  73 +
78 74  
79 75 AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
80 76  
81   - AndroidJavaObject fileObject = new AndroidJavaObject("java.io.File", AndroidPath + Vlibras + FileName);// Set Image Path Here
  77 + AndroidJavaObject fileObject = new AndroidJavaObject("java.io.File", Path.Combine(AndroidPath + Vlibras, FileName));// Set Image Path Here
82 78 AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("fromFile", fileObject);
83 79 // string uriPath = uriObject.Call("getPath");
84 80 bool fileExist = fileObject.Call<bool>("exists");
... ... @@ -89,10 +85,59 @@ public class MediaShareAndroid : MonoBehaviour
89 85 AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
90 86 AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
91 87 currentActivity.Call("startActivity", intentObject);
92   - new AndroidToast().showToast("Vídeo salvo em /Vlibras");
93   -
  88 +
  89 + */
  90 +
94 91 #endif
95 92 }
  93 +
  94 + private void ShareIntent()
  95 + {
  96 + destination = Path.Combine(AndroidPath, Vlibras);
  97 + DirectoryInfo dir = new DirectoryInfo(destination);
  98 + new AndroidToast().showToast(destination);
  99 + if (!dir.Exists)
  100 + {
  101 + dir.Create();
  102 + }
  103 +
  104 + dir = new DirectoryInfo(Path.Combine(destination, FileName));
  105 + if (!dir.Exists)
  106 + {
  107 + FileStream SourceStream = new FileStream(Path.Combine(destination, FileName), FileMode.OpenOrCreate);
  108 + if (SourceStream.CanWrite)
  109 + {
  110 + SourceStream.Write(videoContent, 0, bytes);
  111 + SourceStream.Close();
  112 +
  113 + }
  114 + else
  115 + {
  116 + new AndroidToast().showToast("Erro ao escrever arquivo");
  117 + }
  118 +
  119 + }
  120 +
  121 +
  122 + // block to open the file and share it ------------START
  123 + AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
  124 + AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
  125 + intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
  126 + AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
  127 + AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + Path.Combine(destination,FileName));
  128 + intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
  129 + intentObject.Call<AndroidJavaObject>("setType", MediaType);
  130 + //add data to be passed to the other activity i.e., the data to be sent
  131 + intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), SubtitleMessage);
  132 + intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), "Vlibras Video");
  133 + intentObject.Call<AndroidJavaObject>("setType", "video/mp4");
  134 + AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  135 + AndroidJavaObject jChooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, "Compartilhar via");
  136 + AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
  137 + currentActivity.Call("startActivity", jChooser);
  138 +
  139 +
  140 + }
96 141 }
97 142  
98 143  
... ...
Assets/Scripts/UI/ScreenManager.cs
... ... @@ -33,6 +33,7 @@ public class ScreenManager : MonoBehaviour {
33 33 public GameObject downloadProgressLayer;
34 34  
35 35 private bool onLockExport = false;
  36 + private bool onLockShare = false;
36 37  
37 38  
38 39  
... ... @@ -333,7 +334,7 @@ public class ScreenManager : MonoBehaviour {
333 334 setTranslateButtonActive( ! playing);
334 335 setPauseMenuState(playing && paused);
335 336 setRepeatLayerState( ! playing && repeatable);
336   - if(!onLockExport)
  337 + if(!onLockExport && !onLockShare)
337 338 changeExportStates(ExportLayers.ExportLayer.All, !playing && repeatable);
338 339  
339 340  
... ... @@ -345,28 +346,33 @@ public class ScreenManager : MonoBehaviour {
345 346 switch (layers)
346 347 {
347 348 case ExportLayers.ExportLayer.Export_Layer:
  349 + onLockShare = false;
348 350 onLockExport = false;
349 351 setExportContainerState(show_Layer);
350 352 setExportLayerState(show_Layer);
351 353 break;
352 354 case ExportLayers.ExportLayer.Progress_Layer:
353 355 onLockExport = true;
  356 + onLockShare = true;
354 357 setExportContainerState(show_Layer);
355 358 setProgressLayerState(show_Layer);
356 359 break;
357 360 case ExportLayers.ExportLayer.Download_Layer:
358 361 onLockExport = true;
  362 + onLockShare = true;
359 363 setExportContainerState(show_Layer);
360 364 setDownloadLayerState(show_Layer);
361 365 break;
362 366 case ExportLayers.ExportLayer.Progress_Download_Layer:
363 367 onLockExport = true;
  368 + onLockShare = true;
364 369 setExportContainerState(show_Layer);
365 370 setDownloadProgressLayerState(show_Layer);
366 371  
367 372 break;
368 373 case ExportLayers.ExportLayer.Share_Layer:
369   - onLockExport = true;
  374 + onLockExport = true;
  375 + onLockShare = false;
370 376 setExportContainerState(show_Layer);
371 377 setShareLayerState(show_Layer);
372 378 break;
... ... @@ -374,6 +380,7 @@ public class ScreenManager : MonoBehaviour {
374 380 onLockExport = show_Layer;
375 381 break;
376 382 default:
  383 + onLockShare = false;
377 384 onLockExport = false;
378 385 setExportContainerState(show_Layer);
379 386 setExportLayerState(show_Layer);
... ...
ProjectSettings/ProjectSettings.asset
... ... @@ -111,7 +111,7 @@ PlayerSettings:
111 111 iPhoneScriptCallOptimization: 0
112 112 iPhoneBuildNumber: 0
113 113 ForceInternetPermission: 0
114   - ForceSDCardPermission: 0
  114 + ForceSDCardPermission: 1
115 115 CreateWallpaper: 0
116 116 APKExpansionFiles: 0
117 117 preloadShaders: 0
... ...