Flutter WebRTC Playing Audio
Asked Answered
U

1

7

I wish to play audio from remote stream of webrtc connection, in Flutter. The examples of flutter webrtc use RTCVideoRenderer, but there is no video in my case. The remote stream only consists of audio.

In short:

pc.onTrack = (event) {
  // how can I play the Audio stream in event.streams[0] ?
};

Code:

MediaStream _localStream = await createStream();
RTCPeerConnection pc = await createPeerConnection({});

_localStream.getTracks().forEach((track) async => await pc.addTrack(track, _localStream));  

pc.onTrack = (event) {
  // how can I play the Audio stream in event.streams[0] ?
};
    
Future<MediaStream> createStream() async {
  final Map<String, dynamic> mediaConstraints = {
    'audio': true,
    'video': false
  };

  MediaStream stream = await MediaDevices.getUserMedia(mediaConstraints);
  return stream;
}

How can I play the audio from remote stream in flutter?

Unwitnessed answered 27/2, 2021 at 10:8 Comment(2)
I think it need to add to a video renderer.Prepay
Hi. Were you able to play the audio on your part? Please suggest if you found something. Thanks!Telfer
C
0

Audio will play automatically in this case, you don't need a renderer if the track is audio only.

Cothurnus answered 2/3, 2024 at 11:53 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Sheepcote

© 2022 - 2025 — McMap. All rights reserved.