2

我希望在 Flutter 中播放来自 webrtc 连接的远程流的音频。flutter webrtc 使用的例子RTCVideoRenderer,但我的案例中没有视频。远程流仅包含音频。

简而言之:

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

代码:

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;
}

如何在颤动中播放来自远程流的音频?

4

0 回答 0