2
private void UploadVideo(string FileName, string VideoTitle, string VideoDescription)
        {
            try
            {
                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
                });

                video.Snippet = new VideoSnippet();
                video.Snippet.Title = VideoTitle;
                video.Snippet.Description = VideoDescription;
                video.Snippet.Tags = new string[] { "tag1", "tag2" };
                video.Status = new VideoStatus();
                video.Status.PrivacyStatus = "public";
                using (var fileStream = new FileStream(FileName, FileMode.Open))
                {

                    const int KB = 0x400;
                    var minimumChunkSize = 256 * KB;

                    var videosInsertRequest = youtubeService.Videos.Insert(video,
                        "snippet,status", fileStream, "video/*");
                    videosInsertRequest.ProgressChanged +=
                        videosInsertRequest_ProgressChanged;
                    videosInsertRequest.ResponseReceived +=
                        videosInsertRequest_ResponseReceived;
                    // The default chunk size is 10MB, here will use 1MB.
                    videosInsertRequest.ChunkSize = minimumChunkSize * 3;
                    dt = DateTime.Now;
                    totalBytes = fileStream.Length;
                    videosInsertRequest.Upload();
                    videosInsertRequest.UploadAsync();
                }
            }
            catch (Exception errors)
            {
                string errorss = errors.ToString();
            }
        }

Untill now i used to upload a video file only with the line:

videosInsertRequest.Upload();

And on the description of Upload it says: Uploads the content to the server. This method is sync and will block untill the upload is complete.

And the UploadAsync description say: Uploads the content async to the server.

If i have a List of video files and i want to upload them all parallel i mean to upload some videos at the same time how can i do it ?

Or maybe if i will use UploadAsync so if i click a button and each time it will upload a different file name video file they will be upload at the same time parallel ?

In other words i think that: my question should be how can i upload more then one video file to youtube at the same time ?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Daniel van wolf
  • 393
  • 1
  • 5
  • 16
  • 1
    possible duplicate of [Asynchronous vs synchronous execution, what does it really mean?](http://stackoverflow.com/questions/748175/asynchronous-vs-synchronous-execution-what-does-it-really-mean) – NASSER Sep 10 '15 at 11:18
  • if you try and upload more then one at the same time aren't you going to have a problem with the user quota? if I upload 10 vidoes at once I am still only allowed to send 10 requests a second. so each video would only get to upload one chunk a second where as if you did it one video at a time you would upload 10 chunks a second. – Linda Lawton - DaImTo Sep 10 '15 at 11:49
  • DalmTo ok maybe another way then. Each time i will click a button to upload a new video file it will add the video files to a queue somehow and will upload the video files automatic i mean once it finished uploading one file it will take from the queue the next video file and will upload it and so on. Maybe i could use a List or a queue somehow my general idea is to have a batch of video file i will click a button and "forget" the video files it will upload them one by one if not at same time. – Daniel van wolf Sep 10 '15 at 12:14

1 Answers1

0
var mResumableUploader = new ResumableUploader(chunkSize);
        mResumableUploader.AsyncOperationCompleted += MResumableUploaderAsyncOperationCompleted;
        mResumableUploader.AsyncOperationProgress += MResumableUploaderAsyncOperationProgress;
mResumableUploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(ru_AsyncOperationCompleted);
        var youTubeAuthenticator = new ClientLoginAuthenticator(appName, ServiceNames.YouTube, uName, passWord);
        youTubeAuthenticator.DeveloperKey = devKey;

        newVideo = new Video();

        newVideo.Title = "video";
        newVideo.Tags.Add(new MediaCategory("Entertainment", YouTubeNameTable.CategorySchema));
        newVideo.Keywords = "video";
        newVideo.Description = "video";
        newVideo.YouTubeEntry.Private = false;
        newVideo.YouTubeEntry.MediaSource = new MediaFileSource(fileName, fileContType);

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

        Console.WriteLine("Starting upload: ");
        mResumableUploader.InsertAsync(youTubeAuthenticator, newVideo.YouTubeEntry, "inserter");

There is the Event of Complete:

void ru_AsyncOperationCompleted(object sender, AsyncOperationCompletedEventArgs e)
        {

        //upload complete
        YouTubeRequestSettings ytSettings = new YouTubeRequestSettings("myApp", googleDevKey, ytUsername, ytPassword);
        Video v = ytRequest.ParseVideo(e.ResponseStream);
        string videoId = v.VideoId;
        string watchPage = v.WatchPage.ToString();

    }
Awn Ali
  • 1,361
  • 1
  • 17
  • 31
  • The question is. "What is the difference between sync and async" this does not answer that question. – Linda Lawton - DaImTo Sep 10 '15 at 11:39
  • Look at the last line of question: In other words i think that: my question should be how can i upload more then one video file to youtube at the same time ? – Awn Ali Sep 10 '15 at 11:42
  • I updated his question then to better reflect the actual question. – Linda Lawton - DaImTo Sep 10 '15 at 11:45
  • still your answer uses YouTube api v2 (gdata). He is using the current version of the YouTube API v3. your code won't work for that its two different client libraries. And V2 has been deprecated for awhile now really wouldnt recommend using it. – Linda Lawton - DaImTo Sep 10 '15 at 11:47