0
我需要一個代碼爲youtube縮略圖與播放按鈕,它從URL獲取視頻ID後點擊播放視頻將播放彈出...任何人都可以建議...?需要代碼爲youtube縮略圖與播放按鈕後,我點擊播放視頻將彈出
的.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代碼我得到的數據列表YouTube視頻,但是當我點擊它,它起着因爲它是在200像素* 200像素。
你會舉個例子嗎? – Gaurav 2013-05-01 08:45:39