本文介绍了需要code YouTube的缩略图,播放按钮后,我点击播放视频将在弹出播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个code YouTube的缩略图,播放按钮,获取从URL中的视频ID后,我点击播放视频将在弹出的播放...任何人都可以提出...?

i need a code for youtube thumbnail with play button which fetch the video id from url after i click to play the video will play in popup... can anyone suggest...?

的.aspx code:

.aspx code:

<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 code

.aspx.cs code

    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 $ C C I得到DataList的YouTube视频,但是当我点击它,它起着因为它是在200像素* 200像素。

from ablove code i get youtube video in datalist but when i click to it it plays as it is in 200px*200px.

推荐答案

我会做这个是不同的。

就个人而言,我倒是没有嵌入视频,因为这就是问题所在!相反,嵌入视频或类似的图片,的onclick然后加载在新窗口中选择相应的视频。

Personally, I'd not embed the video as this is the problem! Instead, embed a picture of the video or similar, the onclick then loads the appropriate video in a new window.

更新您的模板太

<ItemTemplate>
             Description:
             <asp:Label ID="DescriptionLabel" runat="server"
                 Text='<%# Eval("Description") %>' />
             <br />
         <a href="wherever" javacriptCommandToOpenPopUpHere><img src="picture.jpg"></a>
<br /><br />
</ItemTemplate>

您可能还需要更新您的Insert命令,因为它可能会允许SQL注入。

You may also need to update your Insert command as it may allow for SQL injection.

这篇关于需要code YouTube的缩略图,播放按钮后,我点击播放视频将在弹出播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 23:05