使用MVC播放音频和视频文件 [英] Play audio and video file using MVC
本文介绍了使用MVC播放音频和视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨..
我有来自MS SQL数据库的音频和视频文件我想在浏览器上使用mvc应用程序播放它应该如何播放?
解决方案
使用HTML5< video>
和< audio>
元素:
使用HTML5音频和视频 - Web开发者指南| MDN [ ^ ]
您需要确保拥有支持不同浏览器所需的相关格式:
HTML音频和视频元素支持的媒体格式 - HTML | PHP |网站设计MDN [ ^ ]
要加载视频/音频文件,您需要一个返回文件数据的操作:
public ActionResult视频( int id)
{
var videoData = ...; // 从数据库加载指定视频的字节
return 文件(videoData, video / mp4);
}
< video controls 自动播放 >
< ; source src < span class =code-keyword> = @ Url.Action( 视频, YourController, new { id = Model.VideoId }) 类型 = video / mp4 / >
(旧浏览器的后备内容...)
< / video > 跨度>
Hi..
I have audio and video file which comes from MS SQL database i want to play it on browser using mvc application how should i play it??
解决方案
Use the HTML5<video>
and<audio>
elements:
Using HTML5 audio and video - Web developer guides | MDN[^]
You'll need to make sure you have the relevant formats required to support different browsers:
Media formats supported by the HTML audio and video elements - HTML | MDN[^]
To load the video / audio file, you'll need an action which returns the file data:
public ActionResult Video(int id) { var videoData = ...; // Load the bytes for the specified video from the database return File(videoData, "video/mp4"); }
<video controls autoplay> <source src="@Url.Action("Video", "YourController", new { id = Model.VideoId })" type="video/mp4" /> (Fallback content for old browsers...) </video>
这篇关于使用MVC播放音频和视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文