.net 视频FLV转换原代码

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;


public partial class Admin_HLSP_TJ : System.Web.UI.Page
{
    string[] videoExtension = new string[] { "flv", "avi", "wmv", };
    HLSP_table h = new HLSP_table();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["user"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        //判断用户是否登录
        //if (Session["userName"] == null)
        //{
        //    //未登录给出提示并返回到首页
        //    Response.Write("<script>alert('请您先登录!');location='../index.aspx'</script>");
        //} 

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string upFileName = fileupVideo.FileName;
        //判断是否选择了文件
        if (this.fileupVideo.HasFile)
        {

            //获取文件的扩展名
            string upExtension = upFileName.Substring(upFileName.LastIndexOf(".") + 1);
            //判断扩展名是否正确
            if (checkExtension(upExtension))
            {
                //获取上传文件所保存的路径
                string upFilePath = Server.MapPath("../upFile/") + upFileName;
                //将文件保存到指定路径中
                fileupVideo.SaveAs(upFilePath);
                //获取当前时间
                string saveName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                //获取视频转换后所保存的路径及文件名
                string playFile = "playFile/" + saveName + ".flv";
                //获取图片所保存的路径及名称
                string imgFile = "imgFile/" + saveName + ".jpg";

                try
                {
                    //判断上传的文件是否为flv格式
                    if (upExtension == "flv")
                    {
                        //如果为flv格式直接保存到指定路径下
                        File.Copy(fileupVideo.PostedFile.FileName, Server.MapPath("../" + playFile));
                        //调用公共类中的catchImg方法截取视频图片
                        operateMethod.catchImg(Server.MapPath("../" + playFile), Server.MapPath("../" + imgFile));
                        //调用自定义insertVideoInfo方法将视频的信息保存到数据库中
                        insertVideoInfo(playFile, imgFile);
                        if (System.IO.File.Exists(Server.MapPath("~/upFile/" + upFileName)))
                        {
                            System.IO.File.Delete(Server.MapPath("~/upFile/" + upFileName));
                        }
                        fileupVideo.SaveAs(HttpContext.Current.Server.MapPath(imgFile));
                    }
                    else
                    {
                        //调用公共类中的changeVideoType方法转换视频格式
                        if (operateMethod.changeVideoType(upFileName, Server.MapPath("../") + playFile, Server.MapPath("../") + imgFile))
                        {
                            //调用自定义insertVideoInfo方法将视频信息保存到数据库中
                            insertVideoInfo(playFile, imgFile);

                            //删除上传的视频

                            if (System.IO.File.Exists(Server.MapPath("~/upFile/" + upFileName)))
                            {
                                System.IO.File.Delete(Server.MapPath("~/upFile/" + upFileName));
                            }
                           
                        }
                        else
                        {
                            RegisterStartupScript("false", "<script>alert('上传失败!')</script>");
                            //删除上传的视频
                            if (System.IO.File.Exists(Server.MapPath("~/upFile/" + upFileName)))
                            {
                                System.IO.File.Delete(Server.MapPath("~/upFile/" + upFileName));
                            }

                        }

                    }

                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message.ToString());
                }
            }
            else
            {
                RegisterStartupScript("false", "<script>alert('文件格式错误!')</script>");
            }

        }
    }
    private bool checkExtension(string extension)
    {
        bool strReturn = false;
        //遍历数组判断当前上传的视频格式是否正确
        foreach (string var in this.videoExtension)
        {
            if (var == extension)
            {
                strReturn = true; break;
            }
        }
        return strReturn;

    }
    protected void insertVideoInfo(string playFile, string imgFile)
    {


        string name = TextBox1.Text;
        string shijian = DateTime.Now.ToString();
        string neirong = TextBox2.Text;

        int j = h.Add(name, neirong, playFile, imgFile, shijian);
        if (j > 0)
        {
            Response.Write("<script language=javascript>alert('视频上传成功')</script>");
            Response.Write("<script language=javascript>document.location='HLSP_tianjia.aspx'</script>");
        }


   


    }
}

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值