playStream method

  1. @override
Future<PlayStreamResponse> playStream({
  1. required AudioInfo audioInfo,
  2. required Stream<Uint8List> audioStream,
  3. Map<String, dynamic>? extra,
})
override

Stream audio chunks to this audio output device for playback.

The caller provides a Stream of raw audio bytes; each chunk must match the codec and format described by audioInfo. Playback begins on the device as chunks arrive, before the stream is exhausted.

Implementation

@override
Future<PlayStreamResponse> playStream({
  required AudioInfo audioInfo,
  required Stream<Uint8List> audioStream,
  Map<String, dynamic>? extra,
}) async {
  final init = PlayStreamRequest()
    ..init = (PlayStreamInit()
      ..name = name
      ..audioInfo = audioInfo
      ..extra = extra?.toStruct() ?? Struct());

  Stream<PlayStreamRequest> requests() async* {
    yield init;
    await for (final chunk in audioStream) {
      yield PlayStreamRequest()..audioChunk = (PlayStreamChunk()..audioData = chunk);
    }
  }

  return await client.playStream(requests());
}