Skip to main content Link Menu Expand (external link) Document Search Copy Copied
startPlayerFromStream method - FlutterSoundPlayer class - player library - Dart API
menu
startPlayerFromStream

startPlayerFromStream method

Future<void> startPlayerFromStream({
  1. Codec codec = Codec.pcm16,
  2. bool interleaved = true,
  3. int numChannels = 1,
  4. int sampleRate = 16000,
  5. int bufferSize = 8192,
})

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.

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

Implementation

Future<void> startPlayerFromStream({
  Codec codec = Codec.pcm16,
  bool interleaved = true,
  int numChannels = 1,
  int sampleRate = 16000,
  int bufferSize = 8192,
  //TWhenFinished? whenFinished,
}) async {
  await _lock.synchronized(() async {
    await _startPlayerFromStream(
      codec: codec,
      interleaved: interleaved,
      sampleRate: sampleRate,
      numChannels: numChannels,
      bufferSize: bufferSize,
      //whenFinished: whenFinished,
    );
  });
}
flutter_sound 9.25.3