C# or VB.NET code for two-way audio

Have some questions or having issues with your IP Camera(s), Post them here for the mods and other users to assist you with.
Post Reply
swabygw
Posts: 5
Joined: Mon Dec 07, 2020 12:13 am

C# or VB.NET code for two-way audio

Post by swabygw »

I have the IP4M-1051 model Amcrest camera. I cannot get my VB.NET code to send audio to the camera successfully (you can see my code below). Does anyone have a C# or VB.NET example of this feature (sending audio from PC-to-camera) working successfully?

Code: Select all


        Dim client As HttpClient
        Dim handler As New WebRequestHandler
        Dim result As New HttpResponseMessage
        Dim CommandString, ResultString As String
        Dim CancelTokenSource As New CancellationTokenSource
        Dim CancelToken As CancellationToken = CancelTokenSource.Token

        CommandString = "http://192.168.1.80/cgi-bin/audio.cgi?action=postAudio&httptype=singlepart&channel=1"

	Using handler
                handler.Credentials = New NetworkCredential("admin", "password")
                client = New HttpClient(handler)
                Using client
                    client.BaseAddress = New Uri(CommandString)
                    'client.Timeout = TimeSpan.FromMilliseconds(5000)
                    'client.DefaultRequestHeaders.Add("Content-Type", "Audio/PCM")
                    'client.DefaultRequestHeaders.Add("Content-Length", bytesRecorded)
                    client.DefaultRequestHeaders.Add("Connection", "Keep-Alive")
                    client.DefaultRequestHeaders.Add("Keep-Alive", "3600")

                    'result = Await client.GetAsync(CommandString, HttpCompletionOption.ResponseContentRead, CancelToken)
                    Dim byteContent As ByteArrayContent = New ByteArrayContent(buffer)
                    byteContent.Headers.ContentType = New MediaTypeHeaderValue("Audio/AAC")
                    byteContent.Headers.ContentLength = bytesRecorded

                    System.Net.ServicePointManager.Expect100Continue = False
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

                    result = Await client.PostAsync(CommandString, byteContent)
                    'CameraErrorCount = 0
                    Using result
                        '    result.EnsureSuccessStatusCode()
                        '    ResultString = Await result.Content.ReadAsStringAsync
                        '    If Not ResultString.ToUpper.Contains("OK") Then 'AndAlso Not Action.ToUpper.Contains("STATUS") Then
                        '        Console.WriteLine("ResultString: " & ResultString)
                        '    End If
                    End Using
                End Using
            End Using
Post Reply