Dot*_*row 4 c# asp.net asp.net-mvc
我正在开发 asp.net 应用程序,并且我正在从我的角度调用控制器操作。该视图需要将 mp3 返回给被调用的函数。Actionresult 的类型是什么。被调用的函数返回 mp3 响应。如何将api返回的mp3响应保存在内存中并返回视图?
这是我的控制器方法代码:
public ActionResult getrecording()
{
byte[] file = new byte[100]; // Convert.ToByte("https://api.abc.com/api/v2/GetRecording?access_token=dfsdfsdfsdfsdfsdfsdfsdfsfsfdsf");
//return (new FileStreamResult(fileStream, "audio/mpeg"));
////return (new FileContentResult(data, "audio/mpeg"));
}
Run Code Online (Sandbox Code Playgroud)
这是查看代码
$("#jquery_jplayer_1").jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
mp3: "/recording/getrecording"
});
},
swfPath: "../../Content/JPlayer/js",
supplied: "mp3",
wmode: "window",
size: 100,
duration: "#duration"
});
Run Code Online (Sandbox Code Playgroud)
您可以使用 WebClient 下载远程文件,然后将其流式传输到响应:
public ActionResult getrecording()
{
var client = new WebClient();
var stream = client.OpenRead("https://api.abc.com/api/v2/GetRecording?access_token=dfsdfsdfsdfsdfsdfsdfsdfsfsfdsf");
return File(stream, "audio/mpeg");
}
Run Code Online (Sandbox Code Playgroud)
如果您希望提示客户端下载文件,只需添加一个名称:
public ActionResult getrecording()
{
var client = new WebClient();
var stream = client.OpenRead("https://api.abc.com/api/v2/GetRecording?access_token=dfsdfsdfsdfsdfsdfsdfsdfsfsfdsf");
return File(stream, "audio/mpeg", "foo.mp3");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2908 次 |
| 最近记录: |