5

これは、Windows フォーム デスクトップ アプリケーションから C# .NET API を使用して Youtube にビデオをアップロードするコードです。

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);

これは機能します。私が探しているのは、アップロードの進行状況を取り戻すイベントです。そのため、進行状況をプログレスバーに表示できます。次のイベントを登録できます。

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

...しかし、アップロード中に解雇されることはありません。また、上記の小さなビデオ アップロードの例よりもはるかに進んだ .NET API に関するドキュメントを見つけることができません。では、これらのイベントを探すのは間違っているのでしょうか? 参考までに、バックグラウンド スレッドの次のコードで一見同期アップロードを開始しています。

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

このようにして、同期操作がいつ終了したかがわかりますが、進行状況の更新に関するイベントをユーザーに提供したいと考えています。何か案は?

4

1 に答える 1

4

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.

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

于 2011-08-02T00:19:10.153 に答える