Orji Emmanuel
Orji Emmanuel

Reputation: 1

Sending audio chunk to ICECAST on Azurecast "Streamer"

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.0\r\n'
            'Authorization: Basic $auth\r\n'
            'Content-Type: audio/mpeg\r\n'
            'Ice-Public: 1\r\n'
            'Ice-Name: My Radio\r\n'
            'Ice-Description: Flutter Streaming\r\n'
            'Ice-Audio-Info: ice-samplerate=$sampleRate;ice-bitrate=$bitRate;ice-channels=$channel\r\n'
            'Ice-Url: http://$serverAddress\r\n'
            'Connection: Keep-Alive\r\n'; 

        _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';
    }

Upvotes: 0

Views: 26

Answers (0)

Related Questions