在Asp.Net应用程序中播放视频 [英] Play Video in Asp.Net application

查看:90
本文介绍了在Asp.Net应用程序中播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码上传视频现在我想在Asp页面上播放。

plzz告诉我任何想法或代码.Thnxx .. !!

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Web.UI.HtmlControls;
使用 System.Data;
使用 System.Data.SqlClient;
使用 System.Web;

public partial class video1:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{

}
byte []缓冲区;
受保护 void Button1_Click( object sender,EventArgs e)
{
{
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName)。降低();
byte [] MediaBytes = new byte [FileUpload1.PostedFile.InputStream.Length];
if (FileUpload1.HasFile&& FileUpload1.PostedFile!= null
&&& FileUpload1.PostedFile.FileName!=
{
HttpPostedFile file = FileUpload1.PostedFile;
buffer = new byte [file.ContentLength];
int bytesReaded = file.InputStream.Read(buffer, 0 ,FileUpload1.PostedFile.ContentLength );
if (bytesReaded > 0
{
try
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = 数据源= DEEPAK-PC\\SQLEXPRESS;初始目录= NewCrackers;用户ID = sa;密码= sasa;
conn.Open();
SqlCommand cmd = new SqlCommand
INSERT INTO Videos(Video,Video_Name,Video_Size)VALUES(@ video,@ videoName,@ videoSize),conn);
cmd.Parameters.Add( @ video,SqlDbType.VarBinary,buffer.Length ).Value =缓冲;
cmd.Parameters.Add( @ videoName,SqlDbType.NVarChar).Value = FileUpload1.FileName;
cmd.Parameters.Add( @ videoSize,SqlDbType.BigInt).Value = file.ContentLength;
使用(conn)
{
cmd.ExecuteNonQuery();
Label1.Text = 已上传;
conn.Close();
}
}
catch (例外情况)
{
Label1.Text = ex.Message。的ToString();
}
}
}
else
{
Label1.Text = 选择有效的视频文件;
}
}
}
}

解决方案

参考: -

如何通过从数据库中提取路径在asp.net网站上播放视频 [ ^ ]


< blockquote>下载Flash控件/ silverlight并将其添加到您的工具箱中。

然后指定控件的路径。



下载flashControl 此处 [ ^ ]和silverlight 这里 [ ^ ]



对于Flash播放器:

 Flash1.MovieURL =   Path; 





Silverlight:

 MediaPlayer1.MediaSource =   路径; 


如果您的目标是新浏览器,那么就不要我需要一个插件。



这个 [ ^ ]是一个可与HTML5视频播放器配合使用的库,但您不需要它,底层他们使用的标签足以在任何现代浏览器上播放视频。


Hii i m uploading video using this code now i want to play this on Asp page.
plzz tell me any idea or code..Thnxx..!!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
using System.Web;

public partial class video1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    byte[] buffer;
    protected void Button1_Click(object sender, EventArgs e)
    {
        {
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
byte[] MediaBytes = new byte[FileUpload1.PostedFile.InputStream.Length];
if (FileUpload1.HasFile && FileUpload1.PostedFile != null
&& FileUpload1.PostedFile.FileName != "")
{
HttpPostedFile file = FileUpload1.PostedFile;
buffer = new byte[file.ContentLength];
int bytesReaded = file.InputStream.Read(buffer, 0, FileUpload1.PostedFile.ContentLength);
if (bytesReaded > 0)
{
try
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=DEEPAK-PC\\SQLEXPRESS;Initial Catalog=NewCrackers;User ID=sa;Password=sasa";
conn.Open();
SqlCommand cmd = new SqlCommand
("INSERT INTO Videos (Video, Video_Name, Video_Size) VALUES (@video, @videoName, @videoSize)", conn);
cmd.Parameters.Add("@video", SqlDbType.VarBinary, buffer.Length).Value = buffer;
cmd.Parameters.Add("@videoName", SqlDbType.NVarChar).Value = FileUpload1.FileName;
cmd.Parameters.Add("@videoSize", SqlDbType.BigInt).Value = file.ContentLength;
using (conn)
{
cmd.ExecuteNonQuery();
Label1.Text = " uploaded ";
conn.Close();
}
}
catch (Exception ex)
{
Label1.Text = ex.Message.ToString();
}
}
}
else
{
Label1.Text = "Choose a valid video file";
}
}
}
}

解决方案

refer:-
How to play a video in asp.net web site by fetching path from database[^]


Download Flash control/silverlight and add it in your toolbox.
Then assign path to the control.

Download flashControl Here[^]and silverlightHere[^]

For Flash player:

Flash1.MovieURL = "Path ";



Silverlight:

MediaPlayer1.MediaSource = "Path ";


If you're targeting new browsers, you don't need a plug in.

This[^] is a library that works with the HTML5 video player, but you don't need it, the underlying tags they are using is more than enough to play video on any modern browser.


这篇关于在Asp.Net应用程序中播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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