N
NYCOM82
Guest
I have a basic recorder with one label and three buttons, Record, Pause/Resume, and Save. The record and save work but not pause. When I click Pause it continues to record. I'm using Visual Studio 2010 Pro in VB.net. The project is a Windows Form App using .NET 4.From what I can find on various forums it should "just work." - but doesn't. No errors reported.
mciSendString always returns 0
Is there something I forgot to import?
Here is what I have so far:
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
Dim sb As New StringBuilder
Dim err As Integer
Dim NotPaused As Boolean = True
Dim sMyRecordingFile As String = "D:\Company\Audio.wav"
<DllImport("winmm.dll")> _
Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
End Function
Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click
Try
err = mciSendString("open new type waveaudio alias MyRecording", Nothing, 0, 0)
Console.WriteLine("open new type waveaudio alias MyRecording " & err)
err = mciSendString("record MyRecording", Nothing, 0, 0)
Console.WriteLine("record MyRecording " & err)
Me.Label1.Text = "Recording"
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
err = mciSendString("save MyRecording " & sMyRecordingFile, Nothing, 0, 0)
Console.WriteLine("save MyRecording " & sMyRecordingFile & err)
err = mciSendString("close MyRecording", Nothing, 0, 0)
Console.WriteLine("close MyRecording " & err)
Me.Label1.Text = "Idle"
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub btnPauseResume_Click(sender As Object, e As System.EventArgs) Handles btnPauseResume.Click
If NotPaused Then
Try
err = mciSendString("pause MyRecording", Nothing, 0, 0)
Console.WriteLine("pause MyRecording " & err)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
NotPaused = False
Me.btnPauseResume.Text = "Resume"
Me.Label1.Text = "Paused"
Else
Try
err = mciSendString("resume MyRecording", Nothing, 0, 0)
Console.WriteLine("resume MyRecording " & err)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
NotPaused = True
Me.btnPauseResume.Text = "Pause"
Me.Label1.Text = "Recording"
End If
End Sub
End Class
Continue reading...
mciSendString always returns 0
Is there something I forgot to import?
Here is what I have so far:
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
Dim sb As New StringBuilder
Dim err As Integer
Dim NotPaused As Boolean = True
Dim sMyRecordingFile As String = "D:\Company\Audio.wav"
<DllImport("winmm.dll")> _
Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
End Function
Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click
Try
err = mciSendString("open new type waveaudio alias MyRecording", Nothing, 0, 0)
Console.WriteLine("open new type waveaudio alias MyRecording " & err)
err = mciSendString("record MyRecording", Nothing, 0, 0)
Console.WriteLine("record MyRecording " & err)
Me.Label1.Text = "Recording"
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
err = mciSendString("save MyRecording " & sMyRecordingFile, Nothing, 0, 0)
Console.WriteLine("save MyRecording " & sMyRecordingFile & err)
err = mciSendString("close MyRecording", Nothing, 0, 0)
Console.WriteLine("close MyRecording " & err)
Me.Label1.Text = "Idle"
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub btnPauseResume_Click(sender As Object, e As System.EventArgs) Handles btnPauseResume.Click
If NotPaused Then
Try
err = mciSendString("pause MyRecording", Nothing, 0, 0)
Console.WriteLine("pause MyRecording " & err)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
NotPaused = False
Me.btnPauseResume.Text = "Resume"
Me.Label1.Text = "Paused"
Else
Try
err = mciSendString("resume MyRecording", Nothing, 0, 0)
Console.WriteLine("resume MyRecording " & err)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
NotPaused = True
Me.btnPauseResume.Text = "Pause"
Me.Label1.Text = "Recording"
End If
End Sub
End Class
Continue reading...