Đây là mã để tải lên một đoạn video lên Youtube bằng cách sử dụng C# .NET API từ một ứng dụng Windows Forms máy tính để bàn:Youtube C# .NET API: Tải lên video và nhận được sự kiện khi hoàn tất
YouTubeRequestSettings settings = new YouTubeRequestSettings("whatwill come here ?",
"my api key",
"my youtube login email", "my youtube login password");
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = "test 1";
newVideo.Tags.Add(new MediaCategory("Gaming", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "test 1 , test 2";
newVideo.Description = "test 3 test 4";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("tag 1, tag 2",
YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\\test.avi", "video/quicktime");
Video createdVideo = request.Upload(newVideo);
này hoạt động. Những gì tôi đang tìm kiếm là các sự kiện giúp tôi quay lại quá trình tải lên, vì vậy tôi có thể hiển thị tiến trình trong thanh tiến trình. Ich có thể đăng ký các sự kiện sau:
request.Service.AsyncOperationProgress +=
new AsyncOperationProgressEventHandler(Service_AsyncOperationProgress);
request.Service.AsyncOperationCompleted +=
new AsyncOperationCompletedEventHandler(Service_AsyncOperationCompleted);
... nhưng chúng không bao giờ bị sa thải trong khi tải lên. Ngoài ra, tôi không thể tìm thấy bất kỳ tài liệu nào về .NET api đi xa hơn so với ví dụ tải lên video nhỏ ở trên. Vì vậy: Có phải những sự kiện sai để tìm kiếm? Chỉ để tham khảo, tôi bắt đầu tải lên dường như synchonous trong đoạn mã sau trong một thread nền:
ThreadPool.QueueUserWorkItem(
delegate
{
try
{
createdVideo = request.Upload(newVideo);
} catch (Exception ex){
Invoke((ThreadStart) delegate{uploadingFailedWithException(ex);});
}
});
Invoke((ThreadStart)readyUploading);
Bằng cách này tôi biết khi nào hoạt động synchonous kết thúc, nhưng tôi muốn có sự kiện để cập nhật tiến độ người dùng. Bất kỳ ý tưởng?
Cảm ơn bạn, điều đó nên thực hiện! :-) – Akku