0

我正在开发一个应用程序正在使用 C# 上的 Youtube Api 2.0 将视频上传到 youtube

这是我的代码

    Video newVideo = new Video();

    newVideo.Title = "kankaaaa";
    newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
    newVideo.Keywords = "education, funny deneme";
    newVideo.Description = "bilgi mi istiyorsun";
    newVideo.YouTubeEntry.Private = false;
    newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",
    YouTubeNameTable.DeveloperTagSchema));
    newVideo.YouTubeEntry.MediaSource = new MediaFileSource("c:\\cat.flv",
          "video/quicktime");      
   // newVideo.Private = true;

 Video createdVideo = Request.Upload(newVideo);

Video 类位于Google.YouTube 命名空间下。

我可以毫无问题地上传视频。当请求完成时,它返回一个类型为视频的对象。

但我想看看处理的细节。我的意思是上传的百分比。我搜索了两个函数,getUploadState() 和 getProgress()。但我在 youtube api 上找不到它。

Video 类只有Status 类成员。它显示了视频的结果。但我想学习上传过程的详细信息。比如完成了40%..

我应该使用什么?我认为我可以使用 Backgroundworker,但我不确定它是否有效。

4

1 回答 1

1

我解决了自己的问题..有点困难,但我终于做到了:)

public bool InsertVideo()
    {
        Trace.TraceInformation("Entering InsertVideo: starting a new upload");
        Video newVideo = new Video();

        newVideo.Title = "MY video";
        newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
        newVideo.Keywords = "education, funny deneme";
        newVideo.Description = "bilgi mi istiyorsun";
        newVideo.YouTubeEntry.Private = false;
        newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",
          YouTubeNameTable.DeveloperTagSchema));

        newVideo.YouTubeEntry.MediaSource = new MediaFileSource("c:\\cat.flv",
          "video/quicktime");
        // newVideo.Private = true;

        GDataCredentials credentials = new GDataCredentials(UserName, PassWord);

        Authenticator youTubeAuthenticator =new ClientLoginAuthenticator("YoutubeUploader",
                    ServiceNames.YouTube, credentials);
        youTubeAuthenticator.DeveloperKey = DevKey;


        AtomLink link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/" + UserName + "/uploads");
        link.Rel = ResumableUploader.CreateMediaRelation;
        newVideo.YouTubeEntry.Links.Add(link);

        ResumableUploader ru = new ResumableUploader();
        ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(this.OnDone);
        ru.AsyncOperationProgress += new AsyncOperationProgressEventHandler(this.OnProgress);
        var tmpvalue = "bla bla bla";
        ru.InsertAsync(youTubeAuthenticator, newVideo.YouTubeEntry, tmpvalue);



        return true;
    }

    private void OnProgress(object sender, AsyncOperationProgressEventArgs e)
    {
       Debug.WriteLine("It has been completed : " + e.ProgressPercentage);
    }

    private void OnDone(object sender, AsyncOperationCompletedEventArgs e)
    {

        Debug.WriteLine("It has Done");
    }

您可以使用 AsyncOperationCompletedEventArgs e 参数访问 OnDone 事件中上传视频的信息,属性为 ResponseStream

于 2012-09-02T22:08:20.680 回答