initialize method

Future<void> initialize({
  1. int bufferSize = 4096 << 3,
  2. int nChannels = 1,
  3. int sampleRate = 16000,
  4. RawSoundPCMType pcmType = RawSoundPCMType.PCMI16,
})

Initializes the player

Throws an Exception if the player is already initialized

The bufferSize is only valid for Android to set up the buffer size of the underlying AudioTrack

The nChannels should either be 1 or 2 to indicate the number of channels

The sampleRate is the sample rate for output

The pcmType determines the raw PCM format

Implementation

Future<void> initialize({
  int bufferSize = 4096 << 3,
  int nChannels = 1,
  int sampleRate = 16000,
  RawSoundPCMType pcmType = RawSoundPCMType.PCMI16,
}) async {
  print('RS:---> initialize');

  await _lock.synchronized(() async {
    _ensureUninited();

    await RawSoundPlayerPlatform.instance.initialize(
      this,
      bufferSize: bufferSize,
      nChannels: nChannels,
      sampleRate: sampleRate,
      pcmType: pcmType.index,
    );
    _playState = PlayState.stopped;
    _isInited = true;
  });

  print('RS:<--- initialize');
}