如何在Youtube Api上获取视频的上传状态



我正在开发一个应用程序,正在用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);

视频类位于Google.Uube命名空间下

我可以上传视频,没有任何问题。当请求完成时,它返回一个类型为"视频"的对象。

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

只有视频类的状态类成员。它显示了视频的结果。但我想了解上传过程的细节。比如完成了40%。。

我应该用什么?我原以为我可以做背景工作者,但我不确定它是否有效。

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

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

相关内容

  • 没有找到相关文章

最新更新