有誰知道如何在使用可恢復的上傳時將視頻添加到播放列表?使用可恢復的上傳將視頻添加到播放列表
讓我說清楚。以下是我的代碼。
Video newVideo = new Video();
newVideo.Title = fileName.Split(".".ToCharArray())[0];
newVideo.Tags.Add(new MediaCategory("Nonprofit", YouTubeNameTable.CategorySchema));
newVideo.Description = DateTime.Now.ToShortDateString();
newVideo.YouTubeEntry.Private = false;
ResumableUploader m_ResumableUploader = null;
Authenticator YouTubeAuthenticator;
m_ResumableUploader = new ResumableUploader(100); //chunksize 1 MB
m_ResumableUploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(m_ResumableUploader_AsyncOperationCompleted);
m_ResumableUploader.AsyncOperationProgress += new AsyncOperationProgressEventHandler(m_ResumableUploader_AsyncOperationProgress);
YouTubeAuthenticator = new ClientLoginAuthenticator("YouTubeUploader", ServiceNames.YouTube, ConfigurationManager.AppSettings["USERNAME"].ToString(), ConfigurationManager.AppSettings["PASSWORD"].ToString());
YouTubeAuthenticator.DeveloperKey = ConfigurationManager.AppSettings["DEVELOPER_KEY"].ToString();
string contentType = MediaFileSource.GetContentTypeForFileName(fileName);
newVideo.MediaSource = new MediaFileSource(filePath, contentType);
AtomLink link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/<username>/uploads");
link.Rel = ResumableUploader.CreateMediaRelation;
newVideo.YouTubeEntry.Links.Add(link);
System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
m_ResumableUploader.InsertAsync(YouTubeAuthenticator, newVideo.YouTubeEntry, new object());
我想直接上傳視頻到播放列表。
我正在看這段代碼,我很難連接這兩個。需要幫忙。
https://developers.google.com/youtube/2.0/developers_guide_dotnet
添加視頻到播放列表
您可以通過使用PlayListMember對象的視頻添加到播放列表。以下代碼創建一個具有已知ID值的PlayListMember對象,然後將其添加到播放列表對象(p)中。由於該請求沒有指定視頻在播放列表中出現的位置,因此新視頻將添加到播放列表的末尾。
// For Playlist object p
PlayListMember pm = new PlayListMember();
// Insert <id> or <videoid> for video here
pm.Id = VIDEOID;
request.AddToPlaylist(p, pm);
更新1 - 添加到播放列表時,我得到一個 「不支持的URI格式」 的錯誤。
YouTubeRequestSettings ys = new YouTubeRequestSettings("YouTubeUploader",
ConfigurationManager.AppSettings["DEVELOPER_KEY"].ToString());
YouTubeRequest ytr = new YouTubeRequest(ys);
Video v = ytr.ParseVideo(e.ResponseStream);
PlayListMember pm = new PlayListMember();
Feed<Playlist> userPlaylists = ytr.GetPlaylistsFeed(ytr.Credentials.Username);
foreach (Playlist p in userPlaylists.Entries)
{
fs.WriteLine(p.Title);
if (p.Title == "Test 2")
{
pm.Id = v.VideoId;
ytr.AddToPlaylist(p, pm);
fs.WriteLine("Added To Playlist ");
}
}
可能重複(http://stackoverflow.com/questions/13976749/youtube-api-添加-a-video-to-a-playlist-using-resumable-upload) –
是自己的問題的重複,但是這一次是有據可查的。我想我們應該欣賞現在的努力 – Steve
好的。現在我能得到答覆嗎? –