diff --git a/Assets/Scripts/Export Video/ExportVideo.cs b/Assets/Scripts/Export Video/ExportVideo.cs index 3c90449..dc88cf5 100644 --- a/Assets/Scripts/Export Video/ExportVideo.cs +++ b/Assets/Scripts/Export Video/ExportVideo.cs @@ -207,6 +207,7 @@ public class ExportVideo : MonoBehaviour { if (videoRequestRunning) { StopCoroutine("requestVideoInfo"); + StopCoroutine("VideoStatus"); PlayerLogger.Log("ExportVideo", "OnRequestCancel", "User canceled the request, resetting states to default."); } else if (videoDownloadRunning) @@ -250,76 +251,174 @@ public class ExportVideo : MonoBehaviour { private IEnumerator requestVideoInfo() { - videoRequestRunning = true; - WWWForm JsonRequest = new WWWForm(); - JsonRequest.AddField("gloss", gloss); - WWW videoInfoRequest = new WWW(SERVER_URL, JsonRequest); + + videoRequestRunning = true; + WWWForm JsonRequest = new WWWForm(); + JsonRequest.AddField("gloss", gloss); + WWW videoInfoRequest = new WWW(SERVER_URL, JsonRequest); PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Request for: " + SERVER_URL); yield return WaitForResponse(videoInfoRequest); - try - { - if (!videoInfoRequest.isDone) + try { + if (!videoInfoRequest.isDone) + { + + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + GetConnectionStatusError(ExportLayers.ConnectionStatusError.CONNECTION_TIMEOUT_FAILURE); + PlayerLogger.Log("ExportVideo", "requestVideoInfo", "TimeOut"); + + } + else if (videoInfoRequest.error != null) + { + + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + GetConnectionStatusError(ExportLayers.ConnectionStatusError.INTERNET_CONNECTION_FAILURE); + PlayerLogger.Log("ExportVideo", "requestVideoInfo", "(WWW) Error: " + videoInfoRequest.error); + + } + else if (videoInfoRequest.responseHeaders.Count == 0) + { + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + PlayerLogger.Log("ExportVideo", "requestVideoInfo", "(WWW) Unsucessful Answer"); + GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); + + + + } + else if (!videoInfoRequest.responseHeaders["STATUS"].Contains("200")) + { + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Unsuccessful answer (" + videoInfoRequest.responseHeaders["STATUS"] + ")."); + GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); + + + } + else if (String.IsNullOrEmpty(videoInfoRequest.text)) + { + + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + GetConnectionStatusError(ExportLayers.ConnectionStatusError.DEFAULT); + PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Empty answer."); + + } + else + { + PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Answer: " + videoInfoRequest.text); + + FileContent fileContent = new FileContent(); + fileContent = FileContent.CreateFromJSON(videoInfoRequest.text); + videoId = fileContent.file; + StartCoroutine("VideoStatus"); + + } - screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); - GetConnectionStatusError(ExportLayers.ConnectionStatusError.CONNECTION_TIMEOUT_FAILURE); - PlayerLogger.Log("ExportVideo", "requestVideoInfo", "TimeOut"); - } - else if (videoInfoRequest.error != null) - { - screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); - GetConnectionStatusError(ExportLayers.ConnectionStatusError.INTERNET_CONNECTION_FAILURE); - PlayerLogger.Log("ExportVideo", "requestVideoInfo", "(WWW) Error: " + videoInfoRequest.error); } - else if (videoInfoRequest.responseHeaders.Count == 0) + finally { - screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); - PlayerLogger.Log("ExportVideo", "requestVideoInfo", "(WWW) Unsucessful Answer"); - GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); + videoRequestRunning = false; + } - else if (!videoInfoRequest.responseHeaders["STATUS"].Contains("200")) - { - screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); - PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Unsuccessful answer (" + videoInfoRequest.responseHeaders["STATUS"] + ")."); - GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); + + yield break; + + } - } - else if (String.IsNullOrEmpty(videoInfoRequest.text)) - { + private IEnumerator VideoStatus() + { + + WWWForm JsonRequest = new WWWForm(); + JsonRequest.AddField("id", videoId); + while (true) + { + WWW videoStatusRequest = new WWW(SERVER_URL, JsonRequest); - screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); - GetConnectionStatusError(ExportLayers.ConnectionStatusError.DEFAULT); - PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Empty answer."); - } - else + + yield return WaitForResponse(videoStatusRequest); + + try { - PlayerLogger.Log("ExportVideo", "requestVideoInfo", "Answer: " + videoInfoRequest.text); + if (!videoStatusRequest.isDone) + { - FileContent fileContent = new FileContent(); - fileContent = FileContent.CreateFromJSON(videoInfoRequest.text); - videoId = fileContent.file; - videoSize = int.Parse(fileContent.size); - OnFinishGetVideoInfo(); + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + GetConnectionStatusError(ExportLayers.ConnectionStatusError.CONNECTION_TIMEOUT_FAILURE); + PlayerLogger.Log("ExportVideo", "VideoStatus", "TimeOut"); + break; - yield break; - } + } + else if (videoStatusRequest.error != null) + { + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + GetConnectionStatusError(ExportLayers.ConnectionStatusError.INTERNET_CONNECTION_FAILURE); + PlayerLogger.Log("ExportVideo", "VideoStatus", "(WWW) Error: " + videoStatusRequest.error); + break; - } - finally - { - videoRequestRunning = false; + } + else if (videoStatusRequest.responseHeaders.Count == 0) + { + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + PlayerLogger.Log("ExportVideo", "VideoStatus", "(WWW) Unsucessful Answer"); + GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); + break; - } + } + else if (!videoStatusRequest.responseHeaders["STATUS"].Contains("200")) + { + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + PlayerLogger.Log("ExportVideo", "VideoStatus", "Unsuccessful answer (" + videoStatusRequest.responseHeaders["STATUS"] + ")."); + GetConnectionStatusError(ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE); + break; + + } + else if (String.IsNullOrEmpty(videoStatusRequest.text)) + { + + screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + GetConnectionStatusError(ExportLayers.ConnectionStatusError.DEFAULT); + PlayerLogger.Log("ExportVideo", "VideoStatus", "Empty answer."); + break; + + } + else + { + PlayerLogger.Log("ExportVideo", "VideoStatus", "Answer: " + videoStatusRequest.text); + + + FileContent fileContent = new FileContent(); + fileContent = FileContent.CreateFromJSON(videoStatusRequest.text); + if(fileContent.status == "done") + { + videoSize = int.Parse(fileContent.size); + OnFinishGetVideoInfo(); + break; + } + + yield return new WaitForSeconds(1f); + + + } + + + } + finally + { + videoRequestRunning = false; + } + + yield break; + + + }// while } @@ -395,7 +494,7 @@ public class ExportVideo : MonoBehaviour { public IEnumerator WaitForResponse(WWW www, Events.RequestSuccess success, Events.RequestError error) { - yield return Methods.WaitForResponse(www, 60 * 5f, success, error); + yield return Methods.WaitForResponse(www, 15f, success, error); } diff --git a/Assets/Scripts/Export Video/FileContent.cs b/Assets/Scripts/Export Video/FileContent.cs index 48052d5..5fd85a5 100644 --- a/Assets/Scripts/Export Video/FileContent.cs +++ b/Assets/Scripts/Export Video/FileContent.cs @@ -5,6 +5,7 @@ public class FileContent { public string file; public string size; + public string status; public static FileContent CreateFromJSON(string jsonString) diff --git a/Assets/Scripts/Export Video/FileStatus.cs b/Assets/Scripts/Export Video/FileStatus.cs new file mode 100644 index 0000000..dc6f7fe --- /dev/null +++ b/Assets/Scripts/Export Video/FileStatus.cs @@ -0,0 +1,15 @@ +using UnityEngine; +using System.Collections; + +public class FileStatus : MonoBehaviour { + + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/Assets/Scripts/Export Video/FileStatus.cs.meta b/Assets/Scripts/Export Video/FileStatus.cs.meta new file mode 100644 index 0000000..69622cb --- /dev/null +++ b/Assets/Scripts/Export Video/FileStatus.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: e0091546b0e8aa84681fc5b2da5de595 +timeCreated: 1487781948 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- libgit2 0.21.2