private void BindVideo(string videoId)
{
string sTitle = string.Empty;
bool bPublished = false;
bool bTitle = false;
try
{
XmlTextReader reader = new XmlTextReader("http://gdata.youtube.com/feed/api/videos/" + videoId);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
{
switch (reader.Name)
{
case "published":
bPublished = true;
break;
case "yt:statistics":
{
while (reader.MoveToNextAttribute())
{
if (reader.Name.ToLower().Equals("viewcount"))
sViewCount = reader.Value;
}
}
break;
case "media:title":
bTitle = true;
break;
}
break;
}
case XmlNodeType.Text:
if (bPublished)
{
dtPublishDate = Convert.ToDateTime(reader.Value);
}
else if (bTitle)
{
sTitle = reader.Value;
}
break;
case XmlNodeType.EndElement:
{
bPublished = false;
bTitle = false;
break;
}
}
}
reader.Close();
Response.Write("Published on: " + dtPublishDate.ToLongDateString() + "");
Response.Write("View Count: " + sViewCount + "");
Response.Write("Title: " + sTitle + "");
}
catch { }
}
{
string sTitle = string.Empty;
bool bPublished = false;
bool bTitle = false;
try
{
XmlTextReader reader = new XmlTextReader("http://gdata.youtube.com/feed/api/videos/" + videoId);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
{
switch (reader.Name)
{
case "published":
bPublished = true;
break;
case "yt:statistics":
{
while (reader.MoveToNextAttribute())
{
if (reader.Name.ToLower().Equals("viewcount"))
sViewCount = reader.Value;
}
}
break;
case "media:title":
bTitle = true;
break;
}
break;
}
case XmlNodeType.Text:
if (bPublished)
{
dtPublishDate = Convert.ToDateTime(reader.Value);
}
else if (bTitle)
{
sTitle = reader.Value;
}
break;
case XmlNodeType.EndElement:
{
bPublished = false;
bTitle = false;
break;
}
}
}
reader.Close();
Response.Write("Published on: " + dtPublishDate.ToLongDateString() + "");
Response.Write("View Count: " + sViewCount + "");
Response.Write("Title: " + sTitle + "");
}
catch { }
}