简体   繁体   中英

Live audio stream using tcp indy10

From their example http://www.delphiarea.com/products/delphi-packages/waveaudio/ (TLiveAudioRecorder)

//sender
    procedure TMainForm.LiveAudioRecorderData(Sender: TObject;
      const Buffer: Pointer; BufferSize: Cardinal; var FreeIt: Boolean);
    var
      I: Integer;
    begin
      FreeIt := True;
      for I := tcpServer.Socket.ActiveConnections - 1 downto 0 do
        with tcpServer.Socket.Connections[I] do
          if Data = Self then // the client is ready
            SendBuf(Buffer^, BufferSize);

    end;

How can I send the audio stream using TCP indy10 ? something like Connection.IOHandler.Write(Buffer, 0, true);

You can either:

  1. Use RawToBytes() to copy the buffer data to a TIdBytes and then pass that to TIdIOHandler.Write(TIdBytes) :

     Connection.IOHandler.Write(RawToBytes(Buffer^, BufferSize)); 
  2. Use TIdMemoryBufferStream to wrap the buffer in a TStream and pass that to TIdIOHandler.Write(TStream) :

     Strm := TIdMemoryBufferStream.Create(Buffer, BufferSize); Connection.IOHandler.Write(Strm); Strm.Free; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM