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?