【问题标题】:How do I get uploading status of Video on Youtube Api?如何在 Youtube Api 上获取视频的上传状态?
【发布时间】:2012-09-02 14:25:30
【问题描述】:

我正在开发一个应用程序,正在使用 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.YouTube 命名空间下。

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

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

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

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

【问题讨论】:

    标签: c# youtube-api status uploading


    【解决方案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");
        }
    

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

    【讨论】:

      猜你喜欢
      • 2011-11-25
      • 1970-01-01
      • 1970-01-01
      • 2012-08-29
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 2014-04-10
      相关资源
      最近更新 更多