示例#1
0
        private IEnumerator SendTusRequest()
        {
            ReadBytes();

            m_uploadRequest = UnityWebRequest.Put(m_url, bytes);
            SetupTusRequest(m_uploadRequest);
            m_uploadRequest.method = "PATCH";
            m_uploadRequest.SetRequestHeader("Upload-Offset", m_lastByteUploaded.ToString());
            m_uploadRequest.SetRequestHeader("Content-Type", "application/offset+octet-stream");

            m_isUploading = true;

            yield return(VimeoApi.SendRequest(m_uploadRequest));

            if (m_uploadRequest.isNetworkError || m_uploadRequest.isHttpError)
            {
                UploadError(m_uploadRequest.responseCode + ": " + m_uploadRequest.error);
            }
            else
            {
                m_isUploading         = false;
                m_isFinishedUploading = true;
                if (OnChunkUploadComplete != null)
                {
                    OnChunkUploadComplete(this, m_uploadRequest.GetResponseHeader("Upload-Offset"));
                }
            }

            DisposeBytes();
        }
示例#2
0
        void Start()
        {
            if (_camera == null)
            {
                _camera = Camera.main;
            }

            if (_camera == null)
            {
                Debug.LogWarning("VimeoPublisher: No camera was specified.");
                return;
            }

            recorder = _camera.GetComponent <VimeoRecorder>();

            if (recorder == null)
            {
                recorder = _camera.gameObject.AddComponent <VimeoRecorder>();
                Debug.Log("VimeoRecorder automatically added to " + _camera.name + ": " + recorder);
            }

            api       = gameObject.AddComponent <VimeoApi> ();
            api.token = GetVimeoToken();

            api.OnPatchComplete  += VideoUpdated;
            api.OnUploadComplete += UploadComplete;
            api.OnUploadProgress += UploadProgress;

            if (recordOnStart)
            {
                BeginRecording();
            }
        }
示例#3
0
        IEnumerator GetTicket()
        {
            if (OnUploadProgress != null)
            {
                OnUploadProgress("Authorizing", 0);
            }

            WWWForm form = new WWWForm();

            form.AddField("type", "streaming");

            using (UnityWebRequest request = UnityWebRequest.Post(API_URL + "/me/videos", form)) {
                PrepareHeaders(request, "3.2");
                yield return(VimeoApi.SendRequest(request));

                if (IsNetworkError(request))
                {
                    Debug.LogError(request.error);
                }
                else
                {
                    VimeoTicket ticket = VimeoTicket.CreateFromJSON(request.downloadHandler.text);

                    if (ticket.error == null)
                    {
                        StartCoroutine(UploadVideo(ticket));
                    }
                    else
                    {
                        Debug.LogError(ticket.error + " " + ticket.developer_message);
                    }
                }
            }
        }
示例#4
0
        private void Start()
        {
            if (accessToken != null)
            {
                api                    = gameObject.AddComponent <VimeoApi>();
                api.token              = accessToken;
                api.OnRequestComplete += OnLoadVimeoVideoComplete;
            }

            if (videoScreen != null)
            {
                video = gameObject.AddComponent <VideoController>();
                video.videoScreenObject = videoScreen;

                if (audioSource)
                {
                    video.audioSource = audioSource.GetComponent <AudioSource>();
                }
                video.OnVideoStart += VideoStarted;
                video.OnPlay       += VideoPlay;
                video.OnPause      += VideoPaused;
            }

            // Bootup video
            if (vimeoVideoId != null)
            {
                LoadVimeoVideo(int.Parse(vimeoVideoId));
            }
        }
示例#5
0
 public IEnumerator Request(string api_path)
 {
     if (token != null) {
         UnityWebRequest request = UnityWebRequest.Get(API_URL + api_path);
         PrepareHeaders(request);
         yield return VimeoApi.SendRequest(request);
         ResponseHandler(request);
     }
 }
示例#6
0
 IEnumerator Put(string api_path)
 {
     if (token != null) {
         byte[] data = new byte[] { 0x00 };
         using (UnityWebRequest request = UnityWebRequest.Put(API_URL + api_path, data)) {
             PrepareHeaders(request);
             yield return VimeoApi.SendRequest(request);
             ResponseHandler(request);
         }
     }
 }
示例#7
0
        public IEnumerator RequestTusResource(string api_path, long fileByteCount)
        {
            string tusResourceRequestBody = "{ \"upload\": { \"approach\": \"tus\", \"size\": \"" + fileByteCount.ToString() + "\" } }";

            if (token != null) {
                using (UnityWebRequest request = UnityWebRequest.Put("https://api.vimeo.com/me/videos", tusResourceRequestBody)) {
                    PrepareTusHeaders(request);
                    yield return VimeoApi.SendRequest(request);
                    ResponseHandler(request);
                }
            }
        }
        private void Start()
        {
            if (GetVimeoToken() != null)
            {
                api                    = gameObject.AddComponent <VimeoApi>();
                api.token              = GetVimeoToken();
                api.OnRequestComplete += OnLoadVimeoVideoComplete;
            }

            if (videoScreen == null)
            {
                Debug.LogWarning("No video screen was specified.");
            }



            controller = gameObject.AddComponent <VideoController>();
            controller.videoScreenObject = videoScreen;

            controller.OnVideoStart += VideoStarted;
            controller.OnPlay       += VideoPlay;
            controller.OnPause      += VideoPaused;


            if (audioSource && audioSource.GetType() == typeof(GameObject))
            {
                if (audioSource.GetComponent <AudioSource>() != null)
                {
                    controller.audioSource = audioSource.GetComponent <AudioSource>();
                }
                else
                {
                    Debug.LogWarning("No AudioSource component found on " + audioSource.name + " GameObject");
                }
            }


            // Bootup video
            if (vimeoVideoId != null && vimeoVideoId != "")
            {
                vimeoVideoId = Regex.Split(vimeoVideoId, "/?([0-9]+)")[1];
                LoadVimeoVideo(int.Parse(vimeoVideoId));
            }
            else
            {
                Debug.LogWarning("No Vimeo video ID was specified");
            }
        }
示例#9
0
        private void OnRequestError(string error)
        {
            var settings = target as VimeoSettings;

            Destroy(api);
            api = null;

            settings.signInError = true;

            if (OnFetchError != null)
            {
                OnFetchError.Invoke("");
            }

            Debug.LogError("[VimeoFetcher] Error: " + error);
        }
示例#10
0
        private void InitAPI()
        {
            var settings = target as VimeoSettings;

            if (api == null)
            {
                if (settings.gameObject.GetComponent <VimeoApi>())
                {
                    api = settings.gameObject.GetComponent <VimeoApi>();
                }
                else
                {
                    api = settings.gameObject.AddComponent <VimeoApi>();
                }
            }

            api.token = settings.GetVimeoToken();
        }
示例#11
0
        private void GetVideosComplete(string response)
        {
            var settings = target as VimeoSettings;

            settings.vimeoVideos.Clear();

            api.OnRequestComplete -= GetVideosComplete;
            api.OnError           -= OnRequestError;

            Destroy(api);
            api = null;

            var      json      = JSONNode.Parse(response);
            JSONNode videoData = json["data"];

            if (videoData.Count == 0)
            {
                settings.vimeoVideos.Add(new VimeoVideo("(No videos found)"));
            }
            else
            {
                settings.vimeoVideos.Add(new VimeoVideo("---- Select a video ----", null));

                for (int i = 0; i < videoData.Count; i++)
                {
                    settings.vimeoVideos.Add(
                        new VimeoVideo(videoData[i])
                        );
                }
            }

            Debug.Log("[VimeoFetcher] Completed with " + (settings.vimeoVideos.Count - 1) + " existing videos");

            if (OnFetchComplete != null)
            {
                OnFetchComplete.Invoke(response);
            }
        }
示例#12
0
        private IEnumerator ResumeUpload()
        {
            yield return(new WaitForSeconds(5)); // Wait a bit before trying again so there is time to reconnect

            // Make a request to check what the last upload offset is...
            UnityWebRequest uploadCheck = UnityWebRequest.Get(m_url);

            uploadCheck.method = "HEAD";
            SetupTusRequest(uploadCheck);

            yield return(VimeoApi.SendRequest(uploadCheck));

            if (uploadCheck.GetResponseHeader("Upload-Offset") != null)
            {
                m_lastByteUploaded = long.Parse(uploadCheck.GetResponseHeader("Upload-Offset"));
            }

            uploadCheck.Dispose();
            m_uploadRequest.Dispose();
            m_uploadRequest = null;
            DisposeBytes();
            Upload();
        }
示例#13
0
 void Start()
 {
     recorder  = camera.GetComponent <MovieRecorder> ();
     api       = gameObject.AddComponent <VimeoApi> ();
     api.token = accessToken;
 }