I am developing an application is uploading video to youtube with Youtube Api 2.0 on C#
Here is my code
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 class is under Google.YouTube namespace.
I can upload video without any problem. When Requested completed it returns an object which type is Video.
But I want to see detail of processing. I mean percent of uploading. I searched and I found two functions are getUploadState() and getProgress(). But I cant find it on youtube api.
there is just Status class member of the Video Class. It shows result of video. But I want to learn uploading process detail. Such as 40% completed..
What should I use ? I thought that I could Backgroundworker but I am not sure if it works.
I solved my own problem.. it was a bit difficult but I finally did :)
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");
}
And you can access information of uploaded video in OnDone event with AsyncOperationCompletedEventArgs e parameter and property is ResponseStream