我在看這個flash錄音機: http://code.google.com/p/wami-recorder/WAMI記錄在.NET
有沒有人成功地實現了它在.NET(特別MVC3 C#)?我在網站上看到的所有內容都是PHP實現,沒有實際的演示站點。
另外,如果有人有很好的聲音錄製替代品,那就太好了。謝謝!
我在看這個flash錄音機: http://code.google.com/p/wami-recorder/WAMI記錄在.NET
有沒有人成功地實現了它在.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);
}