首先我得到我所有的youtube視頻列表。 在videosList和videosUrl中有89個項目。 然後,當它變得前往路線:爲什麼我在listBox1_SelectedIndexChanged事件中收到異常?
this.listBox1.SelectedIndex = 80;
它跳到事件:listBox1_SelectedIndexChanged當它做行內:
axWindowsMediaPlayer1.URL = videosUrl[listBox1.SelectedIndex];
,我發現了異常:
類型爲 的'未處理的異常mscorlib.dll中發生'System.Reflection.TargetInvocationException'
附加信息: 調用的目標引發異常。
不知道爲什麼會發生。
即使我現在嘗試將此行更改爲索引0:this.listBox1.SelectedIndex = 0;
我得到相同的異常。
static List<string> videosList = new List<string>();
static List<string> videosUrl = 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)
{
// From the API response, extract the playlist ID that identifies the list
// of videos uploaded to the authenticated user's channel.
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;
// Retrieve the list of videos uploaded to the authenticated user's channel.
var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();
foreach (var playlistItem in playlistItemsListResponse.Items)
{
videosList.Add(playlistItem.Snippet.Title + " " + playlistItem.Snippet.ResourceId.VideoId);
videosUrl.Add("http://www.youtube.com/v/" + playlistItem.Snippet.ResourceId.VideoId);
listBox1.Items.Add(playlistItem.Snippet.Title + " " + playlistItem.Snippet.PublishedAt);
}
nextPageToken = playlistItemsListResponse.NextPageToken;
}
}
if (this.listBox1.Items.Count > 80)
{
this.listBox1.SelectedIndex = 80;
axWindowsMediaPlayer1.URL = videosUrl[80];
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = videosUrl[listBox1.SelectedIndex];
}
UPDATE
我用現在試圖趕上了,使異常的行。 什麼我看到的是第一:
基地= { 「異常類型的 'System.Windows.Forms.AxHost + InvalidActiveXStateException' 被拋出。」}
然後堆棧跟蹤:
在AxWMPLib.AxWindowsMediaPlayer。 set_URL(字符串值) 在Automatic_Record.Youtuber.listBox1_SelectedIndexChanged(對象發件人,EventArgs e)在d:\ C-夏普\ Automatic_Record \ Automatic_Record \ Automatic_Record \ Youtuber.cs:線393
線393是:
axWindowsMediaPlayer1.URL = videosUrl[listBox1.SelectedIndex];
videosUrl contains 89 items。 在索引0我看到videosUrl:http://www.youtube.com/v/gJSXvCiCMCw 而listBox1.SelectedIndex是0
我現在也檢查了我的YouTube,第一視頻爲罰款我可以發揮它沒有問題。
你不得不看在InnerException中知道出了什麼問題。我的水晶球說你需要將呼叫轉移到Load事件的方法。 –
在innerException中,我看到null和裏面:_COMPlusExceptionCode = -532462766 –
你是否在使用後臺線程? – ChrisF