这是我用来将视频文件上传到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/