How to Save the voice record file in the client system Using MCI in c# .net 2.0 web application
-
c# .net 2.0 web application. I have tried following code.It is working fine in Server box (I have created vitrual direcory for record folder in c: drive "), but it not working in client box.
c:\\record\\record.wav"
Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic.Devices;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;public partial class Recording : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{} \[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)\] private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback); protected void btnRecord\_Click(object sender, EventArgs e) { //Record mciSendString("open new Type waveaudio Alias recsound", "", 0, 0); mciSendString("record recsound", "", 0, 0); } protected void btnSaveStop\_Click(object sender, EventArgs e) { // stop and save mciSendString("save recsound c:\\\\record\\\\record.wav", "", 0, 0); mciSendString("close recsound ", "", 0, 0); Computer c = new Computer(); c.Audio.Stop(); } protected void btnRead\_Click(object sender, EventArgs e) { //Read Computer computer = new Computer(); computer.Audio.Play("c:\\\\record\\\\record.wav", AudioPlayMode.Background); }
}
Thanks, Bruze
-
c# .net 2.0 web application. I have tried following code.It is working fine in Server box (I have created vitrual direcory for record folder in c: drive "), but it not working in client box.
c:\\record\\record.wav"
Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic.Devices;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;public partial class Recording : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{} \[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)\] private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback); protected void btnRecord\_Click(object sender, EventArgs e) { //Record mciSendString("open new Type waveaudio Alias recsound", "", 0, 0); mciSendString("record recsound", "", 0, 0); } protected void btnSaveStop\_Click(object sender, EventArgs e) { // stop and save mciSendString("save recsound c:\\\\record\\\\record.wav", "", 0, 0); mciSendString("close recsound ", "", 0, 0); Computer c = new Computer(); c.Audio.Stop(); } protected void btnRead\_Click(object sender, EventArgs e) { //Read Computer computer = new Computer(); computer.Audio.Play("c:\\\\record\\\\record.wav", AudioPlayMode.Background); }
}
Thanks, Bruze
This is the basics of ASP.NET. If you play audio using Computer.Audio.Play it will always run in the server. What you have to do is to download the wav file to the client and then invoke the browser media object installed to run your wav file. For simplicity you can also use
Body BgSound ="~/record.wav"
I recommend to read basic books before you do programming in Web Environment, as there is some problems in the basics of this environment. Hope you understand. :cool: Also on your problem if you are using BgSound or anything, always refer to the Virtual path, as Physical path of your server is different from the clients. ;)
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
This is the basics of ASP.NET. If you play audio using Computer.Audio.Play it will always run in the server. What you have to do is to download the wav file to the client and then invoke the browser media object installed to run your wav file. For simplicity you can also use
Body BgSound ="~/record.wav"
I recommend to read basic books before you do programming in Web Environment, as there is some problems in the basics of this environment. Hope you understand. :cool: Also on your problem if you are using BgSound or anything, always refer to the Virtual path, as Physical path of your server is different from the clients. ;)
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
Thanks For Your Reply. Actually, First of all I want to record the audio and Save into Client box using browser.Once I recorded the audio file then Upload into Server folder. Thanks, Bruze
modified on Monday, September 21, 2009 5:29 PM
Yes. Say you upload a file into the server say
abc.wav
save this file into a directory which is within the virtual path. sayc:\mywebsite\xyz
folder. so that you can callhttp://yourserver.com/xyz/abc.wav
Now create your webpage such that it plays audio using this path.. not your original physical path. Finally take any of the different steps mentioned here to play your sound in the browser: http://www.phon.ucl.ac.uk/home/mark/audio/play.htm[^] Hope you understand this. :)Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
Yes. Say you upload a file into the server say
abc.wav
save this file into a directory which is within the virtual path. sayc:\mywebsite\xyz
folder. so that you can callhttp://yourserver.com/xyz/abc.wav
Now create your webpage such that it plays audio using this path.. not your original physical path. Finally take any of the different steps mentioned here to play your sound in the browser: http://www.phon.ucl.ac.uk/home/mark/audio/play.htm[^] Hope you understand this. :)Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
c# .net 2.0 web application. I have tried following code.It is working fine in Server box (I have created vitrual direcory for record folder in c: drive "), but it not working in client box.
c:\\record\\record.wav"
Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic.Devices;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;public partial class Recording : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{} \[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)\] private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback); protected void btnRecord\_Click(object sender, EventArgs e) { //Record mciSendString("open new Type waveaudio Alias recsound", "", 0, 0); mciSendString("record recsound", "", 0, 0); } protected void btnSaveStop\_Click(object sender, EventArgs e) { // stop and save mciSendString("save recsound c:\\\\record\\\\record.wav", "", 0, 0); mciSendString("close recsound ", "", 0, 0); Computer c = new Computer(); c.Audio.Stop(); } protected void btnRead\_Click(object sender, EventArgs e) { //Read Computer computer = new Computer(); computer.Audio.Play("c:\\\\record\\\\record.wav", AudioPlayMode.Background); }
}
Thanks, Bruze
hi through this code i am recording audios and listening locally but I am unable to record audios on online(production server).its showing empty file.recording not happening there. Please suggest me my code as follows protected void btnSaveStop_Click(object sender, EventArgs e) { shortPath = Server.MapPath("~/Audios/" + txtTag.Text + ".wav"); formatShortPath = string.Format("save recsound \"{0}\"", shortPath); mciSendString(string.Format("{0}", formatShortPath), null, 0, 0); mciSendString("save recsound ", "", 0, 0); mciSendString("close recsound ", "", 0, 0); Computer c = new Computer(); c.Audio.Stop(); }
modified on Friday, March 12, 2010 1:08 AM