我在看这个闪存录音机: http ://code.google.com/p/wami-recorder/
有没有人在.NET(特别是 MVC3 C#)中成功实现它?我在站点中看到的只是 PHP 实现,没有实际的演示站点。
此外,如果有人有很好的录音替代品,那就太好了。谢谢!
我在看这个闪存录音机: http ://code.google.com/p/wami-recorder/
有没有人在.NET(特别是 MVC3 C#)中成功实现它?我在站点中看到的只是 PHP 实现,没有实际的演示站点。
此外,如果有人有很好的录音替代品,那就太好了。谢谢!
您需要做的就是设置 recordUrl 和 playUrl
作为基本实现,您可以执行以下操作:
@{
var payUrl = "http://yourdomain/recordings/recording-" + Session["recordingId"] + ".wav";
<!-- saves the wav file to local folder called recodings using a session value to make unique file names -->
}
<script>
function setupRecorder() {
Wami.setup({
id: "wami",
onReady: setupGUI
});
}
function setupGUI() {
var gui = new Wami.GUI({
id: "wami",
recordUrl: "http://yourdomain/home/Save",
playUrl: "@payUrl"
});
gui.setPlayEnabled(false);
}
</script>
并在您的家庭控制器中添加保存操作
public ActionResult Save()
{
Request.SaveAs(Server.MapPath("/recordings/recording-" + Session["recordingId"].ToString() + ".wav"), false);
return Json(new {Success = true}, JsonRequestBehavior.AllowGet);
}
将以下代码放入您的页面中:
<div id="wami"></div>
后面的代码如下:
protected override void OnPreRender(EventArgs e) {
ScriptManager.RegisterStartupScript(Page, GetType(), "setupRecorder", "setupRecorder();", true);
base.OnPreRender(e);
}
创建一个网页,比如RecorderPage.aspx,将 html 留空,并将以下代码放入后面的代码中:
private const string Path = "/App_Data/recordings";
private static readonly string FileName = string.Format("audio-{0}-{1}.wav", DateTime.Now.ToString("yyyyMMdd"), Guid.NewGuid());
private static readonly string Directory = HttpContext.Current.Server.MapPath(Path);
protected void Page_Load(object sender, EventArgs e) {
string mapPath = HttpContext.Current.Server.MapPath(Path);
string action = Request.QueryString["action"];
if (!action.HasValue()) {
return;
}
if (action.Equals("save")) {
if (!System.IO.Directory.Exists(Directory)) {
System.IO.Directory.CreateDirectory(Directory);
}
Request.SaveAs(Server.MapPath(Path + "/" + FileName), false);
} else if (action.Equals("play")) {
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.BufferOutput = true;
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Type", "audio/x-wav");
HttpContext.Current.Response.ContentType = "audio/x-wav";
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
Response.WriteFile(mapPath + "/" + FileName);
HttpContext.Current.Response.Expires = -1;
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
}
确保正确导入所有必需的文件(buttons.png、gui.js、recorder.js 和 Wami.swf)。
最后,将这两个函数包含在页面的脚本部分中,recordUrl
根据playUrl
您的配置进行修改:
function setupRecorder() {
Wami.setup({
id: "wami",
onReady: setupGUI
});
}
function setupGUI() {
var gui = new Wami.GUI({
id: "wami",
recordUrl: "http://localhost/RecorderPage.aspx?action=save",
playUrl: "http://localhost/RecorderPage.aspx?action=play"
});
gui.setPlayEnabled(false);
}