Monday, July 8, 2013

Media Player using ASP.net C#


protected void btnSave_Click(object sender, EventArgs e)
    {
        string fname = Path.GetFileName(flupUpload.PostedFile.FileName.ToString());
        string ext = Path.GetExtension(fname);
       
            if (flupUpload.HasFile)
            {
                flupUpload.SaveAs(Server.MapPath("fileCollection/" + fname));
                string ins = "insert into tbl_upload(file_caption,file_name)values('" + txtcaption.Text + "','" + fname + "')";
                obj.execute_Query(ins);
            }
       
    }
    protected void btnShow_Click(object sender, EventArgs e)
    {
        string sel = "select * from tbl_upload";
        obj.fillGrid(grdFiles, sel);
    }

    protected void grdFiles_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "play")
        {
            int id = Convert.ToInt32(e.CommandArgument.ToString());
            Response.Redirect("Player.aspx?fid=" + id + "");
        }
    }
  
}

Player Page
public partial class MediaPlayer_Player : System.Web.UI.Page
{
    public static string videoname;
    Cls_ADO obj = new Cls_ADO();
    protected void Page_Load(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Request.QueryString["fid"]);
        string str = "select * from tbl_upload where file_id=" + id + "";
        DataTable dt = new DataTable();
        dt = obj.select_Query(str);
        if (dt.Rows.Count > 0)
        {
            videoname = dt.Rows[0]["file_name"].ToString();
        }
    }
}

Source Code
<table class="style1">
            <tr>
                <td>
                    <object id="mediaPlayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
                        codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
                        standby="Loading Microsoft Windows Media Player components..."
                        style="width: 846px; height: 416px;" type="application/x-oleobject">
        <param name="fileName" value="fileCollection/<%=videoname %>" />
                        <param name="animationatStart" value="true" />
                        <param name="transparentatStart" value="true" />
                        <param name="autoStart" value="true" />
                        <param name="showControls" value="true" />
                        <param name="loop" value="true" />
   <embed id="EMBED1" autosize="-1" autostart="true" bgcolor="darkblue"
                            designtimesp="5311" displaysize="4" height="285" loop="true" name="mediaPlayer"
                            pluginspage="http://microsoft.com/windows/mediaplayer/en/download/"
                            showcontrols="true" showdisplay="0" showstatusbar="-1" showtracker="-1"
                         
src="fileCollection/<%=videoname %>"
type="application/x-mplayer2" videoborder3d="-1" width="320"></embed>
      </EMBED>
      </object>
                </td>
            </tr>

        </table>

No comments:

Post a Comment