在不使用showdialog的情况下在C#中保存.wav文件 [英] saving .wav files without showdialog in C#

查看:114
本文介绍了在不使用showdialog的情况下在C#中保存.wav文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我不希望用户决定所记录的WAV文件应保存在哪个位置,wav文件应保存在c:\中.例如,当单击按钮2时,wav文件将保存到"c:\".我希望你们能帮助我.

Problem: I don't want the user to decide which location the recorded WAV file should be saved,the wav file should save in c:\ . for example when button 2 is clicked the wav file saves to "c:\". I hope you guys can help me.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


//voice recorder

namespace recorder
{
   public partial class Form1 : Form
   {   
      [DllImport("winmm.dll")]
      private static extern int mciSendString(string MciComando, string MciRetorno, int MciRetornoLeng, int CallBack);

      string musica = "";

      public Form1()
      {
         InitializeComponent();
      }

      private void Form1_Load(object sender, EventArgs e)
      {
         label1.Visible = false;         //label1.Text=recording
      }


//starts recording what I say to mic

      private void btnStart_Click(object sender, EventArgs e)


      {
         label1.Visible = true;
         mciSendString("open new type waveaudio alias Som", null, 0, 0);
         mciSendString("record Som", null, 0, 0);
      }

//stops recording and shows a save form
//This is where the problem is.
/* I don't want the program to ask the user for location and file name and format to be    
saved as. I just want the file to save in c:\ with the filename "recording1" with format 
as .wav */

      private void btnStopnSave_Click(object sender, EventArgs e)
      {


         label1.Visible = false;
         mciSendString("pause Som", null, 0, 0);
         SaveFileDialog save = new SaveFileDialog();
         save.Filter = "WAVE|*.wav";

         if (save.ShowDialog() == DialogResult.OK) // this is where it needs to be altered
         {
            mciSendString("save Som " + save.FileName,null,0, 0);
            mciSendString("close Som", null, 0, 0);
         }
      }

//lets user to open a WAV file by browsing files

      private void btnPlay_Click(object sender, EventArgs e)
      {

         if (musica == "")                          
         {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Wave|*.wav";
            if (open.ShowDialog() == DialogResult.OK) { musica = open.FileName; }
         }
         mciSendString("play " + musica, null, 0, 0);
      } 
   }
}

推荐答案

只显示对话框而不放置常量字符串,而不使用类SaveFileDialog的实例.

Just don't show the Dialog and put a constant string instead of using the instance of class SaveFileDialog.

var fileName = "C:/mySound.wav";
mciSendString("save Som " + fileName,null,0, 0);
mciSendString("close Som", null, 0, 0);

这篇关于在不使用showdialog的情况下在C#中保存.wav文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆