MVC音频控制按字节播放歌曲 [英] MVC audio controls playing song from bytes
本文介绍了MVC音频控制按字节播放歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的歌曲以字节[]的形式存储在数据库中.如何在<audio>
标记中使用它们.
I have my songs stored in database as bytes[]. How do I use these in the <audio>
tag.
是这样的.我是否需要先将字节转换为其他字节?我不确定.
So something like this. Do I need to convert the bytes to something else first? I am not sure.
foreach (var item in Model)
{
<audio controls>
<source src=@item.SongBytes type="audio/mp3"/>
</audio>
}
推荐答案
一种方法是在您的控制器中添加一个新操作以返回数据:
One way would be to add a new action in your controller that returns the data:
public ActionResult Audio(int someId)
{
byte[] songBytes;
// Add code to get data
return new FileStreamResult(songBytes, "audio/mp3");
}
然后将URL放入src属性:
Then put the URL to that into the src attribute:
foreach (var item in Model)
{
<audio controls>
<source src="/Controller/Audio/@item.someId" type="audio/mp3"/>
</audio>
}
这篇关于MVC音频控制按字节播放歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文