为什么当检查上传到youtube处理状态的视频文件时,结果总是为空
本文关键字:文件 结果 的视频 状态 检查 处理 youtube 为什么 | 更新日期: 2023-09-27 18:07:38
这是我用来上传视频文件到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();
}
}
在这个事件中,我创建了一个计时器:
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,看到我的视频文件已经在线处理,它在我的程序中仍然是空的。
我想每隔10秒实时检查一次,看看视频是否仍处于处理模式,以及处理模式何时结束。
您有以下代码
while (true)
{
string status = video.Status.UploadStatus;
}
在UploadVideo()方法的末尾。这是怎么回事,无限循环?这是永远不会结束的