2009-07-15 11 views
0

C# 2008 SP1C#에서 콜백 재생이 완료되었습니다.

다음 코드를 사용하여 녹음 내용을 저장, 재생 및 저장을 중지합니다. 모든 것이 잘 작동합니다. 그러나 재생이 끝나면 다시 호출 할 콜백을 추가하고 싶습니다.

나는 winmm.dll 라이브러리를 사용하여 P/Invoke입니다.

조언에 대해 감사드립니다.

public partial class SoundTest : Form 
    { 
     const uint SND_ASYNC = 0x0001; 
     const uint SND_FILENAME = 0x00020000; 
     const uint SND_NODEFAULT = 0x0002; 

     [DllImport("winmm.dll")] 
     private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, 
               int returnLength, int hwndCallBack); 

     [DllImport("winmm.dll")] 
     private static extern bool PlaySound(string pszsound, UIntPtr hmod, uint fdwSound); 

     public SoundTest() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      // Disable stop button 
      this.btnSaveStop.Enabled = false; 
     } 

     private void btnRecord_Click(object sender, EventArgs e) 
     { 
      // Disable play and record button 
      this.btnRecord.Enabled = false; 
      this.btnPlay.Enabled = false; 
      // Enable stop button 
      this.btnSaveStop.Enabled = true; 

      // Record from microphone 
      mciSendString("Open new Type waveaudio Alias recsound", "", 0, 0); 
      mciSendString("record recsound", "", 0, 0);  
     } 

     private void btnSaveStop_Click(object sender, EventArgs e) 
     { 
      // Enable play and record 
      this.btnRecord.Enabled = true; 
      this.btnPlay.Enabled = true; 
      // Disable Stop button 
      this.btnSaveStop.Enabled = false; 
      mciSendString("save recsound c:\\record.wav", "", 0, 0); 
      mciSendString("close recsound ", "", 0, 0); 
     } 

     private void btnPlay_Click(object sender, EventArgs e) 
     { 
      //// Diable record button while playing back 
      //this.btnRecord.Enabled = false; 
      PlaySound("c:\\record.wav", UIntPtr.Zero, SND_ASYNC | SND_FILENAME | SND_NODEFAULT); 
     } 
    } 

답변

1

는 지금까지 내가 말할 수있는 건,이 작업을 수행 할 수있는 유일한 방법은 당신이는 PlaySound의 API 함수를 호출 직후 callbackfunction 직접 호출하고 SND_ASYNC 대신 SND_SYNC 매개 변수를 전달하는 것입니다.

private void btnPlay_Click(object sender, EventArgs e) 
{ 
    //// Disable record button while playing back 
    //this.btnRecord.Enabled = false; 
    PlaySound("c:\\record.wav", UIntPtr.Zero, SND_SYNC | SND_FILENAME | SND_NODEFAULT); 

    //write your callback code here 
} 
1

'콜백'은 실제로는 Windows 메시지입니다. 폼의 핸들을 hwndcallback으로 전달하고 WndProc를 재정의하면 메시지를 처리 ​​할 수 ​​있습니다.

WndProc here에 대한 추가 정보와 64 비트 친숙한 dllimport 사양 here이 있습니다.

관련 문제