Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Playing live audio from DatagramSocket

$
0
0

Hi,

I was wondering about how I would go about playing live audio from a DatagramSocket. Currently I am sending live microphone data to a server, which is then sending it back to the client. My issue is that I'm not sure how to play the returned audio. This may seem like a weird thing to do, but the reason I'm doing this is because later on in my project I will be broadcasting the same audio data from the server to multiple clients, and I need them to all be able to play it without an issue.

    public void JoinChat() {

        new Thread(() => {

            int minBufSize = AudioTrack.GetMinBufferSize(44100, ChannelOut.Mono, Encoding.Pcm16bit);
            DatagramSocket socket = new DatagramSocket();
            byte[] buffer = new byte[minBufSize];
            DatagramPacket packet;
            InetAddress destination = InetAddress.GetByName(serverAddress);
            recorder = new AudioRecord(AudioSource.Mic, 44100, ChannelIn.Mono, Encoding.Pcm16bit, minBufSize * 10);

            recorder.StartRecording();

            while (status) {

                minBufSize = recorder.Read(buffer, 0, buffer.Length);
                packet = new DatagramPacket(buffer, buffer.Length, destination, port);

                socket.Send(packet);

                //This is the section where I'd like to read the audio data being sent back from the server and then play it through the speakers.

            }

        }).Start();

    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles