如何在Web浏览器中播放音频和视频文件? [英] How to play audio and video files in web browser?

查看:687
本文介绍了如何在Web浏览器中播放音频和视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Button2_Click(object sender, EventArgs e)
{
    UploadLogic bl = new UploadLogic();
    input = ListBox1.SelectedIndex >= 0 ? ListBox1.SelectedItem.ToString() : "";
    DataSet ds = new DataSet();
    ds = bl.Content_details(input);

    if (ds.Tables[0].Rows.Count > 0)
    {
        Byte[] bytes = (Byte[])ds.Tables[0].Rows[0].ItemArray.GetValue(3);
        Response.Buffer = true;

        Response.Charset = "utf-16";

        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");

        Response.ContentType = ds.Tables[0].Rows[0].ItemArray.GetValue(2).ToString();

        Response.AddHeader("content-disposition", string.Format("File_Path; filename={0}", input));

        Response.OutputStream.Write(bytes, 0, input.Length);
        Response.BinaryWrite(bytes);

        Response.Flush();

        Response.End();
    }
    else
    {
        Label1.Text = "No File Found..!";
    }
}

我写这篇code,但它仅下载从数据库文件。如果我想播放音频和视频,那我该怎么办呢?

I wrote this code, but it only downloads the file from the database. If I want to play audio and video, then how can I do it?

推荐答案

都在你的第一个code你只能和发送文件(视频和音频),你认为浏览器知道该怎么做。从另一个侧面的浏览器将决定两种认为,一个显示/播放的一整页你送什么,或者只是问下载。因为是找到FILE_PATH,是决定向下载用户。

First of all in you code you just get and send the file (video or audio) and you think that the browser knows what to do with. The browser from the other side is going to decide in two thinks, one to show/play in a full page what you send, or just ask for download. Because is find the File_Path, is decide to ask the user for the download.

现在如何实际播放音频或网页的视频。大多数浏览器到现在为止并不支持音频/视频和解决方案是使用Adobe Flash播放器的直接播放。使用的是土坯上做了一个播放器,您可以将其发送给它的视频/音频文件(以正确的格式),他可以玩。另外,微软的Silverlight 可以做同样的。

Now how to actually play an audio or a video to web page. Most of browsers until now is not support the direct play of an audio/video and the solution to that is the use of the adobe flash player. Using a player that is made on adobe you can send it to it a video/audio file (to the correct format) and he can play it. Also the Microsoft silverlight can do the same.

现在新的浏览器和HTML 5,可以直接播放音频和视频的页面上。

Now with the new browsers and html 5, you can direct play audio and video on a page.

因此​​,它由你来决定你要遵循,闪光,Silverlight的,HTML5什么样的方式。

So its up to you to decide what way you going to follow, flash,silverlight,html5.

一些例子:

http://www.w3schools.com/html/html_videos.asp

http://www.w3schools.com/html/tryit.asp?文件名= tryhtml_video_html5_4

http://www.web-video-player.com/

http://jplayer.org/latest/demos/

http://flowplayer.org/

http://applian.com/flvplayer/

HTTP://slvideoplayer.$c$cplex.com/

http://openvideoplayer.sourceforge.net/

http://www.longtailvideo.com/players/jw-wmv-player /

让见code的这一部分:

let see this part of code:

<embed width="320" height="240" src="movie.swf">

在此code中的 movie.swf 是你喜欢的播放文件。直接从数据库中你必须做什么得到它是更改到处理程序,并从该处理程序发送该文件。

in this code the movie.swf is the file that you like to play. To direct get it from database what you must do is to change that to a handler and from that handler you send this file.

<embed width="320" height="240" src="loadmovie.ashx?movie.swf">

现在里面的 loadmovie.ashx 您运行code,它从数据库中读取影片/音频,然后将它发送给玩家,而参数从URL行来了。

Now inside the loadmovie.ashx you run your code that reads the movie/audio from the database and then send it to the player, and the parameters are coming from the url line.

我看到你试图说明按钮点击视频。更好的办法是使用打开包含视频的新页面的链接,或打开页面内一个javascript窗口,并显示它,或者只是显示在页面内的div块,并显示它。看看这个例子 http://highslide.com/#examples 在YouTube的W /淡入淡出效果来获得如何在同一页面中打开它,发挥它的想法。

I see that you try to show the video on button click. The better way is to use a link that opens a new page that contains the video, or open a javascript window inside the page and show it, or just show a div block inside the page and show it. Look at this examples http://highslide.com/#examples on the "YouTube w/fade effect" to get an idea for how to open it in the same page and play it.

相关:如何与视频在ASP.NET工作

如何发挥利用声音asp.net中vb.net?

这篇关于如何在Web浏览器中播放音频和视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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