playBytes method

Future<int> playBytes(
  1. Uint8List bytes, {
  2. double volume = 1.0,
  3. Duration? position,
  4. bool respectSilence = false,
  5. bool? stayAwake = false,
  6. bool duckAudio = false,
  7. bool? recordingActive = false,
})

Plays audio in the form of a byte array.

This is only supported on Android currently.

Implementation

Future<int> playBytes(
  Uint8List bytes, {
  double volume = 1.0,
  // position must be null by default to be compatible with radio streams
  Duration? position,
  bool respectSilence = false,
  bool? stayAwake = false,
  bool duckAudio = false,
  bool? recordingActive = false,
}) async {
  stayAwake ??= false;

  if (!Platform.isAndroid) {
    throw PlatformException(
      code: 'Not supported',
      message: 'Only Android is currently supported',
    );
  }

  final int result = await _invokeMethod('playBytes', {
    'bytes': bytes,
    'volume': volume,
    'position': position?.inMilliseconds,
    'respectSilence': respectSilence,
    'stayAwake': stayAwake,
    'duckAudio': duckAudio,
    'recordingActive': recordingActive,
  });

  if (result == 1) {
    state = AudioPlayerState.PLAYING;
  }

  return result;
}