使用.net播放视频和音频文件 [英] Play the videos and audio file using .net

查看:83
本文介绍了使用.net播放视频和音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我目前正在移动网站上工作。该移动网站将使用.net播放网站上的视频和音频文件。我的任务是播放闪存播放器中的文件。



如果您对我的问题有任何解决方案,请为我分享答案。





先谢谢。

解决方案

试试这个。



http://mediaelementjs.com/ [ ^ ]



http://jplayer.org/ [< a href =http://jplayer.org/target =_ blanktitle =New Window> ^ ]


试试这个.... :)



1)VideoPlay.aspx



< html xmlns =   http://www.w3.org/1999/xhtml >  
< head runat = server >
< title> < / title >
< / head >
< body>
< form id = form1 runat = server >
< div>
< table style = width:400px; border = 0 cellpadding = 2 cellspacing = 3 >
< tr>
< td style = width:150px; valign = top >
< / td >
< td style = width:200px; valign = top align = left >
< asp:label id = lblMsg cssclass = tdMessage text = runat = server xmlns:asp = #unknown > < / asp:label >
< / td >
< / tr >
< tr>
< td class = tdText valign = top align = left >
< nobr>选择文件< / nobr >
< / td >
< td style = text-align:left; valign = top >
< asp:fileupload id = fUpload runat = server width = 300px xmlns:asp = #unknown > < / asp:fileupload >
< / td >
< / tr >
< tr>
< td valign = top align = left >
< asp:button id = btnUpload runat = server text = 上传 onclick = < span class =code-string>
btnUpload_Click xmlns:asp = < span class =code-string>#unknown
>
< / asp:按钮 >
< / td >
< td valign = top align = left >
< object classid = clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase = http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0 >
width = 200 height = 100 >
< param name = movie value = <%= swfFileName%> >
< param name = quality value = high >
< embed src = <%= swfFileName%> quality = high pluginspage = http://www.macromedia .com / go / getflashplayer >
type = application / x-shockwave-flash width = 200 height = 1 00 >
< / embed > < / param > < / param > < / object >
< / td >
< / tr >
< / >
&l t; / div >
< / 表格 >
< / body >
< / html >





2)VideoPlay.aspx.cs



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.IO;

命名空间 VideoDemo
{
public partial class VDemo:System.Web.UI.Page
{
public string swfFileName;
受保护 void Page_Load( object sender,EventArgs e)
{

}
protected void btnUpload_Click( object sender,EventArgs e)
{
if (fUpload.FileContent.Length> 0&& IsVaildFile())
{
string Path = GetUplaodImagePhysicalPath();
DirectoryInfo dirUploadImage = new DirectoryInfo(Path);
if (dirUploadImage.Exists == false
{
dirUploadImage.Create();
}
string fileUrl = Path + fUpload.PostedFile.FileName;
fUpload.PostedFile.SaveAs(fileUrl);
swfFileName = images / + fUpload.PostedFile.FileName;
}
}
私有 bool IsVaildFile()
{
string swfExt = System.IO.Path.GetExtension(fUpload.PostedFile.FileName);
switch (swfExt)
{
case 。swf
return ;
默认
{
lblMsg.Text = 请仅选择swf文件。;
return false ;
}
}
}



string GetUplaodImagePhysicalPath()
{
return System.Web.HttpContext.Current.Request.PhysicalApplicationPath + images \\;
}

}

}


如果你使用html5
ex:

 <   html  >  
< 正文 >

< video width = 300 height = 250 控件 = >
< source src = mymovie.mp4 type = video / mp4 >
< source src = mymovie.ogg type = video / ogg >
您的浏览器不支持视频标签。
< / source > < / source > < / video >

< / body >
< / html >


Hi,
I am presently working on mobile site.That mobile site will play the videos and audio files on web site using .net.My task is play the files with out flash player.

If You know any solution for my question,Please share the answer for me.


Thanks in Advance.

解决方案

Try this.

http://mediaelementjs.com/[^]

http://jplayer.org/[^]


Try this....:)

1)VideoPlay.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
    <table style="width: 400px;" border="0" cellpadding="2" cellspacing="3">
        <tr>
            <td style="width: 150px;" valign="top">
            </td>
            <td style="width: 200px;" valign="top" align="left">
                <asp:label id="lblMsg" cssclass="tdMessage" text="" runat="server" xmlns:asp="#unknown"></asp:label>
            </td>
        </tr>
        <tr>
            <td class="tdText" valign="top" align="left">
                <nobr> Select a file</nobr>
            </td>
            <td style="text-align: left;" valign="top">
                <asp:fileupload id="fUpload" runat="server" width="300px" xmlns:asp="#unknown"></asp:fileupload>
            </td>
        </tr>
        <tr>
            <td valign="top" align="left">
                <asp:button id="btnUpload" runat="server" text="Upload" onclick="btnUpload_Click" xmlns:asp="#unknown">
                </asp:button>
            </td>
            <td valign="top" align="left">
                <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0">
                    width="200" height="100">
                    <param name="movie" value="<% =swfFileName%>">
                    <param name="quality" value="high">
                    <embed src="<%=swfFileName%>" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer">
                        type="application/x-shockwave-flash" width="200" height="100">
                </embed></param></param></object>
            </td>
        </tr>
    </table>
    </div>
    </form>
</body>
</html>



2)VideoPlay.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
 
namespace VideoDemo
{
    public partial class VDemo : System.Web.UI.Page
    {
        public string swfFileName;
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
        protected void btnUpload_Click(object sender, EventArgs e)
     {
        if (fUpload.FileContent.Length >0 && IsVaildFile())
        {
            string Path = GetUplaodImagePhysicalPath();
            DirectoryInfo dirUploadImage = new DirectoryInfo(Path);
            if (dirUploadImage.Exists == false)
            {
                dirUploadImage.Create();
            }
            string fileUrl = Path + fUpload.PostedFile.FileName;
            fUpload.PostedFile.SaveAs(fileUrl);
            swfFileName = "images/" + fUpload.PostedFile.FileName;
        }
    }
    private bool IsVaildFile()
    {
        string swfExt = System.IO.Path.GetExtension(fUpload.PostedFile.FileName);
        switch (swfExt)
        {
            case ".swf":
                return true;
            default:
            {
                    lblMsg.Text = "Please select only swf file.";
                    return false;
            }
        }
    }
 

    
    string GetUplaodImagePhysicalPath()
    {
        return System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "images\\";
    }
  
} 
    
}


Use Video tag if you using html5
ex:

<html>
<body>

<video width="300" height="250" controls="">
  <source src="mymovie.mp4" type="video/mp4">
  <source src="mymovie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</source></source></video>

</body>
</html>


这篇关于使用.net播放视频和音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆