# startPlayerFromStream method

Future<void> startPlayerFromStream({

1. required Codec codec,
2. required bool interleaved,
3. required int numChannels,
4. required int sampleRate,
5. required int bufferSize,
6. TWhenFinished? onBufferUnderlow,

})

Used to play something from a dart stream

You use this verb instead of startPlayer when you want to play from a dart stream or if you want to use one of the three `feed()` verbs. For a complete discussion of the play from stream feature, please look to this small guide

## Parameters

- codec: The only codecs supported are Codec.pcm16 and Codec.pcmFloat32. This parameter is mandatory.
- interleaved: is a boolean specifying if the data that you will fee will be in an interleaved or a plan mode. This parameter is mandatory.
- numChannels: is the number of channels of the audio data that you will provide. This parameter is mandatory.
- sampleRate: is the sample rate used by your data. This parameter is mandatory.
- bufferSize: is the size of the internal buffers. Most of the time you don't specify this parameter and use the default value.
- onBufferUnderflow is a callback which is fired when we run short on buffers. Perhaps because the playback is finished or because it has not fully started.

Please look to the following notice

## Return

Returns a Future which is completed when the function is done.

## Example

You can look to the three provided examples :

- This example shows how to play live data, without Back Pressure from Flutter Sound
- This example shows how to play Live data, with Back Pressure from Flutter Sound
- This example shows how to record and playback from streams.

Example 1:

    await myPlayer.startPlayerFromStream(codec: Codec.pcm16, numChannels: 1, sampleRate: 48000);

    await myPlayer.feedF32FromStream(aBuffer);
    await myPlayer.feedF32FromStream(anotherBuffer);
    await myPlayer.feedF32FromStream(myOtherBuffer);

    await myPlayer.stopPlayer();

Example 2:

    await myPlayer.startPlayerFromStream(codec: Codec.pcm16, numChannels: 1, sampleRate: 48000);

    myPlayer.float32Sink.add(aBuffer));
    myPlayer.float32Sink.add(anotherBuffer);
    myPlayer.float32Sink.add(myOtherBuffer);

## See also

- startPlayer()
- stopPlayer()

## Implementation

    Future<void> startPlayerFromStream({
      required Codec codec, // = Codec.pcmFloat32,
      required bool interleaved, // = false,
      required int numChannels, // = 2,
      required int sampleRate, // = 48000,
      required int bufferSize, // = 1024,
      TWhenFinished? onBufferUnderlow,
    }) async {
      await _lock.synchronized(() async {
        await _startPlayerFromStream(
          codec: codec,
          interleaved: interleaved,
          sampleRate: sampleRate,
          numChannels: numChannels,
          bufferSize: bufferSize,
          onBufferUnderflow: onBufferUnderlow,
        );
      });
    }