我需要一个带有播放按钮的 youtube 缩略图代码,在我点击播放视频后从 url 获取视频 ID 将在弹出窗口中播放...有人可以建议...吗?
.aspx 代码:
<asp:DataList ID="DataList3" runat="server" RepeatDirection="Horizontal"
RepeatColumns="7" Width="600px" DataSourceID="SqlDataSource1">
<ItemTemplate>
Description:
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
<object width="200" height="200"><param name="movie" value='<%#DataBinder.Eval(Container.DataItem, "url") %>'></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src='<%#DataBinder.Eval(Container.DataItem, "url") %>' type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="200">
</embed>
</object>
<br />
<br />
</ItemTemplate>
</asp:DataList>
.aspx.cs 代码
string url = txturl.Text;
if (url.Contains("youtube.com"))
{
string ytFormattedUrl = GetYouTubeID(url);
if (!CheckDuplicate(ytFormattedUrl))
{
SqlCommand cmd = new SqlCommand("INSERT INTO YoutubeVideo VALUES ('" + ytFormattedUrl + "','" + lbluser.Text + "','" + title.Text + "','" + DateTime.Today.Date + "','" + DateTime.Now.TimeOfDay + "')", con);
using (con)
{
con.Open();
int result = cmd.ExecuteNonQuery();
if (result != -1)
{
DataList1.DataBind();
}
else { Response.Write("Error inserting new url!"); }
}
}
else { Response.Write("This video already exists in our database!"); }
}
else
{
Response.Write("This URL is not a valid YOUTUBE video link because it does not contain youtube.com in it");
}
}
private string GetYouTubeID(string youTubeUrl)
{
//RegEx to Find YouTube ID
Match regexMatch = Regex.Match(youTubeUrl, "^[^v]+v=(.{11}).*",
RegexOptions.IgnoreCase);
if (regexMatch.Success)
{
return "http://www.youtube.com/v/" + regexMatch.Groups[1].Value +
"&hl=en&fs=1";
}
return youTubeUrl;
}
public bool CheckDuplicate(string youTubeUrl)
{
bool exists = false;
SqlCommand cmd = new SqlCommand(String.Format("select * from YoutubeVideo where url='{0}'", youTubeUrl), con);
using (con)
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
exists = (dr.HasRows) ? true : false;
}
return exists;
}</code>
从 ablove 代码中,我在 datalist 中获得了 youtube 视频,但是当我点击它时,它会以 200px * 200px 的大小播放。