# feedUint8FromStream method

Future<int> feedUint8FromStream(

1. Uint8List buffer

)

Feed a UInt8 stream interleaved when a flow control is wanted

Please look to this small guide if you need help.

## Parameters

- buffer: is a Uint8List containing the audio data that you want to play.

## Return

Returns a Future that you MUST await if you really need a flow control. This future is declared completed when the data has been played, or at least when they had be given to the lower layer of the software. Note: don't use the `int` returned. It is just for legacy reason and must not be used.

## Example

    await myPlayer.startPlayerFromStream
    (
        codec: Codec.pcm16
        numChannels: 2
        sampleRate: 48100
        interleaved: true,
    );

    await myPlayer.feedUint8FromStream(myData);

## See also

- feedInt16FromStream()
- feedF32FromStream()
- float32Sink
- int16Sink
- uint8ListSink
- Please look to this small guide if you need help

## Implementation

    Future<int> feedUint8FromStream(Uint8List buffer) async {
      // await _waitOpen();
      if (_isInited != Initialized.fullyInitialized) {
        throw Exception('Player is not open');
      }
      if (isStopped) {
        return 0;
      }

      if (codec != Codec.pcmFloat32 && codec != Codec.pcm16) {
        logger.e(
          'feedUint8FromStream() : Cannot feed on a Codec <> pcmFloat32 or pcm16',
        );
        throw Exception(
          'feedUint8FromStream() : Cannot feed on a Codec <> pcmFloat32 or pcm16',
        );
      }
      if (!interleaved) {
        logger.e(
          'feedUint8FromStream() : Cannot feed with UInt8 with non interleaved mode',
        );
        throw Exception(
          'feedUint8FromStream() : Cannot feed with UInt8 with non interleaved mode',
        );
      }
      int s = 2;
      if (codec == Codec.pcmFloat32) {
        s = 4;
      }
      double n1 = (buffer.length.toDouble()) / (s * numChannels.toDouble());
      double n2 =
          (buffer.length.toDouble()) / (s * numChannels.toDouble()).round();
      if (n1 != n2) {
        logger.e(
          'feedUint8FromStream() : buffer length (${buffer.length}) is not a multiple of number of channels * $s ($numChannels)',
        );
        throw Exception(
          'feedUint8FromStream() : buffer length (${buffer.length}) is not a multiple of number of channels * $s($numChannels)',
        );
      }

      return _feed(buffer);
    }