startPlayerFromStream method

Future<void> startPlayerFromStream({
  1. Codec codec = Codec.pcm16,
  2. int numChannels = 1,
  3. int sampleRate = 16000,
})

Used to play something from a Dart stream

This functionnality needs, at least, and Android SDK >= 21

  • The only codec supported is actually Codec.pcm16.
  • The only value possible for numChannels is actually 1.
  • SampleRate is the sample rate of the data you want to play.

Please look to the following notice

Example You can look to the three provided examples :

  • This example shows how to play Live data, with Back Pressure from Flutter Sound
  • This example shows how to play Live data, without Back Pressure from Flutter Sound
  • This example shows how to play some real time sound effects.

Example 1:

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

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

await myPlayer.stopPlayer();

Example 2:

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

myPlayer.foodSink.add(FoodData(aBuffer));
myPlayer.foodSink.add(FoodData(anotherBuffer));
myPlayer.foodSink.add(FoodData(myOtherBuffer));

myPlayer.foodSink.add(FoodEvent((){_mPlayer.stopPlayer();}));

Implementation

Future<void> startPlayerFromStream({
  Codec codec = Codec.pcm16,
  int numChannels = 1,
  int sampleRate = 16000,
}) async {
  await _lock.synchronized(() async {
    await _startPlayerFromStream(
      codec: codec,
      sampleRate: sampleRate,
      numChannels: numChannels,
    );
  });
}