Search code examples
flutteraudiowebsocketbinaryreal-time

Flutter play audio directly from binary data from socket


My app receive binary data from socket and need to decode binary data to audio and play realtime directly. i have searched and no library support play audio directly from binary stream realtime.

somebody have any suggestion?


Solution

  • It is possible to play audio bytes on certain platforms using audioplayers plugin. The BytesSource is currently available for Android (See Feature Parity Table), while for other platforms one can use URI encoded bytes. Use the workaround

    UrlSource(Uri.dataFromBytes(bytes, mimeType: mimeType).toString())
    

    found in this GitHub issue

    However, playing audio bytes does mean playing of bytes stream, so, one should implement buffering and maintain gapless playback.

    Edit: To play raw bytes, check flutter_pcm_sound plugin out. Again, buffering is needed to play a stream.