這是從Windows上傳使用C#.NET API到Youtube視頻的代碼越來越事件窗體的桌面應用程序:的Youtube C#.NET API:上傳視頻並在結束時
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);
這工作。我在尋找的是讓我回到上傳進度的事件,所以我可以在進度條中顯示進度。 Ich可以註冊以下活動:
request.Service.AsyncOperationProgress +=
new AsyncOperationProgressEventHandler(Service_AsyncOperationProgress);
request.Service.AsyncOperationCompleted +=
new AsyncOperationCompletedEventHandler(Service_AsyncOperationCompleted);
...但他們從未在上傳過程中被解僱。另外,我找不到任何有關.NET api的文檔,比上面的小視頻上傳示例更進一步。那麼,這些是錯誤的事件嗎?僅供參考,我開始在下面的代碼看似synchonous上傳在後臺線程:
ThreadPool.QueueUserWorkItem(
delegate
{
try
{
createdVideo = request.Upload(newVideo);
} catch (Exception ex){
Invoke((ThreadStart) delegate{uploadingFailedWithException(ex);});
}
});
Invoke((ThreadStart)readyUploading);
這樣,我知道什麼時候該synchonous操作結束了,但我想有進步更新事件用戶。有任何想法嗎?
謝謝,那應該做到這一點! :-) – Akku