ryanheise / audio_service

Flutter plugin to play audio in the background while the screen is off.
802 stars 480 forks source link

Playing audio from remote stream of WebRTC connection #598

Closed AniketBhadane closed 3 years ago

AniketBhadane commented 3 years ago

Is your feature request related to a problem? Please describe. Playing audio received from Remote stream in WebRTC connection.

Describe the solution you'd like

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

Describe alternatives you've considered I did not find an alternative

Additional context The code snippet above shows the requirement

ryanheise commented 3 years ago

This sounds like it should be a separate plugin as audio_service's only goal is to provide a background container for running your existing audio code (invoking other plugins) and providing remote callbacks (e.g. media notification buttons).

AniketBhadane commented 3 years ago

This sounds like it should be a separate plugin as audio_service's only goal is to provide a background container for running your existing audio code (invoking other plugins) and providing remote callbacks (e.g. media notification buttons).

Thank you for the reply. Is there any plugin for Flutter which can play Audio in a MediaStream?

ryanheise commented 3 years ago

I'll close this since the feature is not relevant for audio_service, and my recommendation would be the same as my answer to you on your similar just_audio issue.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.