YouTube的C#.NET API:上传视频并在完成时得到事件 [英] Youtube C# .NET API : Uploading video and getting events when finished

查看:335
本文介绍了YouTube的C#.NET API:上传视频并在完成时得到事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码使用从Windows的C#.NET API的视频上传到YouTube窗体的桌面应用程序:

This is the code to upload a video to Youtube using the C# .NET API from a Windows Forms desktop application:

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可以注册下列事件:

This works. What I'm looking for is the events that get me back the upload progress, so I can show the progress in a progressbar. Ich can register the following events:

                            request.Service.AsyncOperationProgress +=
                            new AsyncOperationProgressEventHandler(Service_AsyncOperationProgress);
                        request.Service.AsyncOperationCompleted +=
                            new AsyncOperationCompletedEventHandler(Service_AsyncOperationCompleted);



...但他们永远无法上传时被解雇。另外,我无法找到有关该走的更远比上方的小视频上传例如.NET API的任何文件。所以说:那些是错的事件寻找?仅供参考,我开始在下面的代码看似synchonous上传在后台线程:

... but they never get fired while uploading. Also, I cannot find any documentation about the .NET api that goes much further than the small video upload example above. So: Are those the wrong events to look for? Just for reference, I'm starting the seemingly synchonous upload in the following code in a background thread:

            ThreadPool.QueueUserWorkItem(
            delegate
                {
                    try
                    {
                        createdVideo = request.Upload(newVideo);
                    } catch (Exception ex){
                      Invoke((ThreadStart) delegate{uploadingFailedWithException(ex);});
                    }
                });
            Invoke((ThreadStart)readyUploading);

这方法,我知道什么时候该synchonous操作结束了,但我想有进度更新事件给用户。任何想法?

This way I know when the synchonous operation ended, but I'd like to have events for progress updates to the user. Any ideas?

推荐答案

您正在使用的上传方法是同步的,正因为如此,你的程序的执行将停止在该行代码,只有当上传完成后继续前进。

The Upload method you are using is synchronous and, as such, the execution of your program will stop on that line of code and only move on when the upload is complete.

你所要做的使用异步上传需要。展示了如何使用ResumableUploader组件和AsyncOperationCompleted / AsyncOperationProgress事件的一个完整的例子包括在.NET客户端库和提供的 http://code.google.com/p/google-gdata/source/browse/#svn%2Ftrunk%2Fclients% 2Fcs%2Fsamples%2FYouTubeUploader%2FYouTubeUploader

What you are trying to do requires using asynchronous upload. A complete example showing how to use the ResumableUploader component and the AsyncOperationCompleted/AsyncOperationProgress events is included in the .NET client library and available at http://code.google.com/p/google-gdata/source/browse/#svn%2Ftrunk%2Fclients%2Fcs%2Fsamples%2FYouTubeUploader%2FYouTubeUploader

这篇关于YouTube的C#.NET API:上传视频并在完成时得到事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆