1

您好我想创建一个简单的网站,允许用户上传和查看视频。我正在使用 asp:literal:Literal1 工具插入 Flash 播放器

经过必要的编码后,我意识到用户可以找到特定的视频网址(例如 "play.aspx?id=<%#Eval("id") %>" ,但问题是当用户进入播放页面时没有显示播放器 我该如何解决?请帮助我...

表示可以找到url请求但无法显示播放器

我的代码:

public partial class play : System.Web.UI.Page
{
    public class operateMethod
    {


        public operateMethod()
        {

        }

        // ▲Show the Flash player and can play video
        public static string GetFlashText(string url)
        {
            url = "player.swf?fileName=" + url;
            string str = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width='452' height='360'  id='index' name='index'><param name='allowScriptAccess' value='always' /><param name='movie' value='" +
                url + "'><embed src='" +
                url + "' id='index1' name='index1' type='application/x-shockwave-flash' swLiveConnect=true allowScriptAccess='always' width='452' height='360'></embed></object>";
            return str;
        }

    }

    public class operateData
    {
        public operateData()
        {

        }

        public static SqlConnection createCon()
        {          
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ToString());
            return con;
        }

        public static SqlDataReader getRow(string sql)
        {
            SqlConnection con = createCon();
            con.Open();
            SqlCommand com = new SqlCommand(sql, con);
            SqlDataReader sdr = com.ExecuteReader();
            return sdr;
        }
    }


    public string Name;        //Publisher
    public string videoTittle; //Video name
    public string videoContent; //Content
    public string videoType;    //videoType

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //判断用户是否登录
            if (Session["userName"] == null)
            {
                //未登录显示登录panel
                PanelLogin.Visible = true;
                //隐藏欢迎panel
                PanelHello.Visible = false;
            }
            else
            {
                //hide login pannel
                PanelLogin.Visible = false;
                //show hello pannel
                PanelHello.Visible = true;
                //show login user name
                lbeUserName.Text = Session["userName"].ToString();
            }

        }
        //Play video
        VideoInfo();

    }

    protected void VideoInfo()
    {
        //set up the script to query the detail info
        string sql = "select * from VideoInfo where id =" + Request["id"];
        SqlDataReader sdr = operateData.getRow(sql);
        sdr.Read();
        //obtain the video path
        string link = sdr["videoPath"].ToString();
        //get the video hit rate
        playSum = sdr["playSum"].ToString();
        //get the number of "likes"
        flower = sdr["flower"].ToString();
        //get the number of "dislikes"
        tile = sdr["title"].ToString();
        //obtain the video publish date
        videoDate = sdr["videoDate"].ToString();
        //get the name of the publisher
        Name = sdr["userName"].ToString();
        //get the video tittle
        videoTittle = sdr["videoTittle"].ToString();
        //obtain the video content
        videoContent = sdr ["videoContent"].ToString();
        //obtain the video type
        videoType = sdr ["videoType"].ToString();
        //judge whether the path starts with 'http://'
        if (!link.StartsWith("http://"))
        {
            //obtain the absolute path
            string sss = Request.Url.AbsoluteUri;
            //locate the location of "play.aspx" at the string
            int idx = sss.IndexOf("play.aspx");
            //get the specified string
            sss = sss.Substring(0,idx);
            link = sss + link;
        }

        //show the player and play video
        this.Literal1.Text = operateMethod.GetFlashText(link);





    }
}

}

4

0 回答 0