我已经在form1设计了一个windows media player控件。 这就是我获取视频列表并将其添加到listBox的方式:
static List<string> videosList = new List<string>();
public async void RetrieveUploadsList()
{
UserCredentials();
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
var channelsListRequest = youtubeService.Channels.List("contentDetails");
channelsListRequest.Mine = true;
var channelsListResponse = await channelsListRequest.ExecuteAsync();
foreach (var channel in channelsListResponse.Items)
{
var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;
Console.WriteLine("Videos in list {0}", uploadsListId);
var nextPageToken = "";
while (nextPageToken != null)
{
var playlistItemsListRequest = youtubeService.PlaylistItems.List("snippet");
playlistItemsListRequest.PlaylistId = uploadsListId;
playlistItemsListRequest.MaxResults = 50;
playlistItemsListRequest.PageToken = nextPageToken;
var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();
foreach (var playlistItem in playlistItemsListResponse.Items)
{
videosList.Add(playlistItem.Snippet.Title + " " + playlistItem.Snippet.ResourceId.VideoId);
listBox1.Items.Add(playlistItem.Snippet.Title + " " + playlistItem.Snippet.PublishedAt);
}
nextPageToken = playlistItemsListResponse.NextPageToken;
}
}
if (this.listBox1.Items.Count > 0)
this.listBox1.SelectedIndex = 0;
}
没有我在listBox中的所有视频列表和已经选择的第一个项目。选择第一个项目后,我想在Windows媒体播放器中显示所选项目视频第一个图像(帧),就像在youtube中看到第一个图像(帧),然后它们开始播放。
而且,当我点击Windows媒体播放器播放按钮时,它将播放视频。 (我是否需要先下载视频?或者它将从youtube上网播放?)
Windows Media Player变量是:
axWindowsMediaPlayer1
我怎样才能做出这两件事?