Beispiel #1
0
        //録画終了
        static async Task EndRecording(HttpListenerContext context)
        {
            WriteLog($"EndRecording");
            var request  = context.Request;
            var response = context.Response;

            var hasOutput     = false;
            var filePath      = "";
            var videoFileName = "";

            lock (syncOutput)
            {
                if (videoOutputStream != null)
                {
                    hasOutput = true;
                    filePath  = videoOutputStream.FileName;
                    WriteLog($"    {filePath}");
                    videoOutputStream.Stop();
                    WriteLog($"    videoOutputStream.Stop");
                    videoOutputStream.Dispose();
                    WriteLog($"    videoOutputStream.Dispose");
                    videoOutputStream = null;
                }
            }

            if (hasOutput)
            {
                videoFileName = GetDateString() + "/" + Guid.NewGuid().ToString() + videoExtension;
                WriteLog($"    {videoFileName}");
                var blob = cloudBlobContainer.GetBlockBlobReference(videoFileName);
                //blob.Properties.ContentType = "video/mp4";
                blob.Properties.ContentType = "video/x-msvideo";
                await blob.UploadFromFileAsync(filePath);

                WriteLog($"    UploadFromFileAsync end");
                // XXX やっぱファイル消すとダメな感じ。await もう少し見よう。
                //File.Delete(filePath);
                //WriteLog($"    File.Delete end");

                response.StatusCode = (int)HttpStatusCode.OK;
            }
            else
            {
                response.StatusCode = (int)HttpStatusCode.NotFound;
            }

            response.ContentType = "application/json";
            response.OutputStream.WriteString(JsonConvert.SerializeObject(
                                                  new
            {
                VideoFileName = videoFileName,
            }
                                                  ));
            response.Close();
        }