Exemplo n.º 1
0
        private void OnCompleteChunk(VideoChunk chunk, string latestUploadedByte)
        {
            if (OnChunckUploadComplete != null)
            {
                OnChunckUploadComplete(chunk, latestUploadedByte);
            }

            if (HasChunksLeftToUpload())
            {
                UploadNextChunk();
            }
            else
            {
                m_isUploading = false;
                ClearAllChunks();

                if (OnUploadProgress != null)
                {
                    OnUploadProgress("UploadComplete", 1f);
                }
                if (OnUploadComplete != null)
                {
                    OnUploadComplete(m_vimeoUrl);
                }
            }
        }
Exemplo n.º 2
0
 private void OnChunkError(VideoChunk chunk, string err)
 {
     m_isUploading = false;
     if (OnChunckUploadError != null && chunk != null)
     {
         OnChunckUploadError(chunk, err);
     }
 }
Exemplo n.º 3
0
        public void UploadNextChunk()
        {
            if (lastChunk != null)
            {
                DisposeChunkEvents(lastChunk);
            }

            currentChunkIndex++;

            VideoChunk currentChunk = m_chunks[currentChunkIndex];

            RegisterChunkEvents(currentChunk);

            currentChunk.Upload();

            //Store the reference to latest uploaded chunk to de-register events
            lastChunk = currentChunk;
        }
Exemplo n.º 4
0
        private void RequestComplete(string response)
        {
            OnRequestComplete -= RequestComplete;

            JSONNode rawJSON = JSONNode.Parse(response);

            string tusUploadLink = rawJSON["upload"]["upload_link"].Value;

            m_vimeoUrl = rawJSON["link"].Value;
            CreateChunks(m_fileInfo, tusUploadLink);

            VideoChunk currentChunk = m_chunks[currentChunkIndex];

            RegisterChunkEvents(currentChunk);
            currentChunk.Upload();

            if (OnUploadInit != null)
            {
                OnUploadInit(response);
            }
        }
Exemplo n.º 5
0
        public void CreateChunks(FileInfo fileInfo, string tusUploadLink)
        {
            //Calculate total number of chunks we are uploading
            m_numChunks = (int)Mathf.Ceil((float)fileInfo.Length / (float)m_maxChunkSize);

            for (int i = 0; i < m_numChunks; i++)
            {
                int        indexByte = m_maxChunkSize * i;
                VideoChunk chunk     = gameObject.AddComponent <VideoChunk>();
                chunk.hideFlags = HideFlags.HideInInspector;

                //If we are at the last chunk set the size to remaining file size
                if (i == m_numChunks - 1)
                {
                    int remainder = (int)fileInfo.Length - (m_maxChunkSize * i);
                    chunk.Init(indexByte, tusUploadLink, fileInfo.FullName, remainder);
                }
                else
                {
                    chunk.Init(indexByte, tusUploadLink, fileInfo.FullName, m_maxChunkSize);
                }
                m_chunks.Add(chunk);
            }
        }
Exemplo n.º 6
0
 public void DisposeChunkEvents(VideoChunk chunk)
 {
     chunk.OnChunkUploadComplete -= OnCompleteChunk;
     chunk.OnChunkUploadError    -= OnChunkError;
 }
Exemplo n.º 7
0
 public void RegisterChunkEvents(VideoChunk chunk)
 {
     chunk.OnChunkUploadComplete += OnCompleteChunk;
     chunk.OnChunkUploadError    += OnChunkError;
 }