有人知道如何添加视频到播放列表时使用恢复上传?
让我说清楚。下面是我的代码。
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 ");
}
}
我明白了。YouTube上的代码有一个错误。它告诉你将PlayListMember id设置为VIDEOID。
// For Playlist object p
PlayListMember pm = new PlayListMember();
// Insert <id> or <videoid> for video here
pm.Id = VIDEOID;
request.AddToPlaylist(p, pm);
这是错误的。您需要将VIDEOID设置为playlistmembervideoid
// For Playlist object p
PlayListMember pm = new PlayListMember();
// Insert <id> or <videoid> for video here
pm.VideoId = VIDEOID;
request.AddToPlaylist(p, pm);
连接这两个操作的是视频id。您需要从第一部分(上传)获得视频id,并将其提供给第二部分(播放列表插入)。因此,问题归结为如何在使用。net客户端库执行可恢复上传时获得新视频的视频id。
我认为这个示例代码专门处理:http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/YouTubeUploader/YouTubeUploader/insertandretry.cs#169