I am trying to connect to Azuracast Streamer using ICECAST, and stream audio chunks to it.
I am able to establish connection to ICECAST but each audio chunk I send through the socket is treated as a new file “For each chunk a new file is created”, instead of concatenating it with the old chunk.
try {
// Establish TCP connection to the Icecast server
_socket = await Socket.connect(serverAddress, int.parse(port));
isActive = _socket != null;
if (isActive) {
// Prepare and send the Icecast headers
String auth = base64Encode(utf8.encode('$username:$password'));
String headers = 'SOURCE $mountPoint HTTP/1.0rn'
'Authorization: Basic $authrn'
'Content-Type: audio/mpegrn'
'Ice-Public: 1rn'
'Ice-Name: My Radiorn'
'Ice-Description: Flutter Streamingrn'
'Ice-Audio-Info: ice-samplerate=$sampleRate;ice-bitrate=$bitRate;ice-channels=$channelrn'
'Ice-Url: http://$serverAddressrn'
'Connection: Keep-Alivern';
_socket!.add(utf8.encode(headers));
// Log the connection status
debugPrint('Connected to Icecast server');
// Start listening to the input stream and server responses
_startListening();
return null;
} else {
return 'Failed to connect to Icecast server';
}
} catch (e) {
// Return the error message
return 'Init failed: $e';
}