c# - 为什么在检查已上传到youtube处理状态的视频文件时,结果始终为空?

标签 c# .net winforms youtube youtube-api

这是我用来将视频文件上传到youtube的上传方法。

static Video video = null;

        private void UploadVideo(string FileName, string VideoTitle, string VideoDescription)
        {
            try
            {
                UserCredential credential;
                using (FileStream stream = new FileStream(@"D:\C-Sharp\Youtube-Manager\Youtube-Manager\Youtube-Manager\bin\Debug\client_secrets.json", FileMode.Open, FileAccess.Read))
                {
                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload },
                        "user",
                        CancellationToken.None,
                        new FileDataStore("YouTube.Auth.Store")).Result;
                }
                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
                });
                video = new Video();
                video.Snippet = new VideoSnippet();
                video.Snippet.Title = VideoTitle;
                video.Snippet.Description = VideoDescription;
                video.Snippet.Tags = new string[] { "tag1", "tag2" };
                video.Status = new VideoStatus();
                video.Status.PrivacyStatus = "public";
                using (var fileStream = new FileStream(FileName, FileMode.Open))
                {

                    const int KB = 0x400;
                    var minimumChunkSize = 256 * KB;

                    var videosInsertRequest = youtubeService.Videos.Insert(video,
                        "snippet,status", fileStream, "video/*");
                    videosInsertRequest.ProgressChanged +=
                        videosInsertRequest_ProgressChanged;
                    videosInsertRequest.ResponseReceived +=
                        videosInsertRequest_ResponseReceived;
                    // The default chunk size is 10MB, here will use 1MB.
                    videosInsertRequest.ChunkSize = minimumChunkSize * 3;
                    dt = DateTime.Now;
                    videosInsertRequest.Upload();
                }
            }
            catch (Exception errors)
            {
                string errorss = errors.ToString();
            }
        }

然后在这种情况下,我要创建一个Timers计时器:
    Video objects = null;
    private void videosInsertRequest_ResponseReceived(Video obj)
    {
        System.Timers.Timer aTimer;
        aTimer = new System.Timers.Timer();
        aTimer.Elapsed += aTimer_Elapsed;
        aTimer.Interval = 10000;
        aTimer.Enabled = true;
        objects = obj;
    }

然后在Elapsed事件中,我正在检查视频文件的处理状态:
void aTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            fff = objects.ProcessingDetails.ProcessingStatus;
        }

但是ProcessingDetails和ProcessingStatus始终为null。
即使我浏览到youtube并看到我的视频文件也已经在线处理,它在我的程序中仍然为null。

我想每10秒钟进行一次实时检查,以查看视频是否仍处于处理模式以及处理模式何时结束。

最佳答案

您有以下代码

 while (true)
 {
       string status = video.Status.UploadStatus;
 }

在UploadVideo()方法的末尾。那应该如何工作-无限循环?它永远不会结束。

关于c# - 为什么在检查已上传到youtube处理状态的视频文件时,结果始终为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31971422/

相关文章:

c# - 套接字异常 : ErrorCode vs. 套接字错误代码

c# - 部署到 Windows Azure 模拟器时 Windows 8 计算机重新启动

c# - 是否可以在 ObjectStateManagerChanged 处理程序中修改实体对象?

.net - (""内的 Response.Redirect "using{ }")

c# - 如何输入标签?

c# - 在方法类的消息框中显示变量

c# - 当元素大小写不一致时反序列化/读取 xml。

javascript - 添加新按钮到 Tinymce 工具栏 C#

c# - 作为属性的接口(interface)

c# - ConfigurationManager.AppSettings - 打开时返回 null