Tutorial Screen-Recording problem step 4

0 votes
asked Sep 18, 2017 by benzou54 (190 points)
Hello, can you develop step 4 of this turtorial. The changes to "HelloARRecording" are not really clear. Can you show us the modified script? Thanks a lot for your work

1 Answer

0 votes
answered Sep 18, 2017 by albert52 (31,850 points)
using System.Collections;

using System.IO;

using UnityEngine;

using UnityEngine.UI;

namespace EasyAR

{

    public class HelloARRecording : MonoBehaviour

    {

        private const string title = "Please enter KEY first!";

        private const string boxtitle = "===PLEASE ENTER YOUR KEY HERE===";

        private const string keyMessage = ""

            + "Steps to create the key for this sample:\n"

            + "  1. login www.easyar.com\n"

            + "  2. create app with\n"

            + "      Name: HelloARRecording (Unity)\n"

            + "      Bundle ID: cn.easyar.samples.unity.helloarrecording\n"

            + "  3. find the created item in the list and show key\n"

            + "  4. replace all text in TextArea with your key";

        public GUISkin skin;

        private bool isRecording = false;

        private bool isShowing = false;

        public bool StartShowMessage = false;

        private bool isClick = false;

        public UILabel label;

        private void Awake()

        {

            var EasyARBehaviour = FindObjectOfType<EasyARBehaviour>();

            if (EasyARBehaviour.Key.Contains(boxtitle))

            {

#if UNITY_EDITOR

                UnityEditor.EditorUtility.DisplayDialog(title, keyMessage, "OK");

#endif

                Debug.LogError(title + " " + keyMessage);

            }

            EasyARBehaviour.Initialize();

            if (ARBuilder.Instance.RecorderBehaviour)

                ARBuilder.Instance.RecorderBehaviour.StatusUpdate += OnRecorderUpdate;

            if (Application.platform == RuntimePlatform.Android)

            {

                DirectoryInfo dir = new DirectoryInfo("/sdcard/Movies/");

                if (!dir.Exists)

                    Directory.CreateDirectory("/sdcard/Movies/");

            }

        }

        public void StartRecord()

        {

            string path_root = Application.persistentDataPath + "/";

            if (Application.platform == RuntimePlatform.Android)

                path_root = "/sdcard/Movies/";

            ARBuilder.Instance.RecorderBehaviour.OutputFile = path_root + "EasyAR_Recording_" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".mp4";

            ARBuilder.Instance.RecorderBehaviour.StartRecording();

            isRecording = true;

            StartShowMessage = true;

        }

        public void StopRecord()

        {

            ARBuilder.Instance.RecorderBehaviour.StopRecording();

            isRecording = false;

            

        }

        public void Record()

        {

            if (!isClick) {

             

                StartRecord ();

                /*

                label.text = "Start";

                label.GetComponent<TweenScale> ().PlayForward ();

                */

                StartCoroutine (showMessage1());

                isClick = true;

            } else {

             

                StopRecord ();

                /*

                label.GetComponent<TweenScale> ().PlayReverse ();

                label.text ="Recorded at " + ARBuilder.Instance.RecorderBehaviour.OutputFile;

                */

                StartCoroutine (showMessage2());

                isClick = false;

            }

        }

         void OnRecorderUpdate(RecorderBaseBehaviour recorder, RecorderBaseBehaviour.Status status, string msg)

        {

            Debug.Log("Recorder Status: " + status + " msg: " + msg);

            if (status == RecorderBaseBehaviour.Status.OnStopped)

                isRecording = false;

        }

        /*

        void OnGUI()

        {

            if (StartShowMessage)

            {

                if (!isShowing)

                    StartCoroutine(showMessage());

                StartShowMessage = false;

            }

            if (isShowing)

            {

                if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)

                    GUI.Box(new Rect(10, Screen.height / 2, Screen.width - 20, 60), "Recorded at " + ARBuilder.Instance.RecorderBehaviour.OutputFile);

                else

                    GUI.Box(new Rect(10, Screen.height / 2, Screen.width - 20, 60), "Recording is available only on Android & iOS. Win32 & Mac will be supported in later EasyAR versions.");

            }

            if (!isRecording)

            {

                if (GUI.Button(new Rect(Screen.width / 2 - 80, Screen.height - 85, 160, 80), "Record", skin.GetStyle("Button")))

                    StartRecord();

            }

            else

            {

                if (GUI.Button(new Rect(Screen.width / 2 - 80, Screen.height - 85, 160, 80), "Stop", skin.GetStyle("Button")))

                    StopRecord();

            }

        }

*/

         

        IEnumerator showMessage1()

        {

            label.gameObject.SetActive (true);

            label.text = "Start";

            yield return new WaitForSeconds(2f);

            label.gameObject.SetActive (false);

        }

        IEnumerator showMessage2()

        {

            label.gameObject.SetActive (true);

            label.text = "Recorded at " + ARBuilder.Instance.RecorderBehaviour.OutputFile;

            yield return new WaitForSeconds(2f);

            label.gameObject.SetActive (false);

        }

    }

}
commented Sep 19, 2017 by benzou54 (190 points)
Thanks for your answer and great work.
I will try with this script and will make you feedback
commented Sep 22, 2017 by benzou54 (190 points)
Hi Albert,
I used your script and it works perfectly on Unity. But i have some problems on my device :
• the video is not recorded in Album library
• if I restart recording, button don't work correctly (color don't change)

Thx for your help

System: OSX Sierra 10.12.6
Xcode: Version 9.0
Device: iPhone iOS 11.0
commented Sep 28, 2017 by memorion (200 points)
on iOS the video is not saved on camera roll :(
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...