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 (SDK >= 23) 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 {
  if (!_isAndroid()) {
    throw PlatformException(
      code: 'Not supported',
      message: 'Only Android is currently supported',
    );
  }

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

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

  return result;
}