audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

Add the capability to set the default route to Speakers or Earpiece (not only toggle)

Open dariocavada opened this issue 4 years ago • 2 comments

Add the capability to set the route to Speakers or Earpiece (before start playing) I did not find this feature in the current implementation and/or examples.

Full Description Using the component as an audio guide inside a museum, for example, it is essential for the user to select the type of earpiece or speaker routing and to be able to maintain this selection throughout his visit.

With the current implementation it is not possible to set the signal routing before playing.

Example Code

Current method for changing signal routing: await _audioPlayer.earpieceOrSpeakersToggle();

Desired method for selecting the signal routing before start playing the audio file:

for Speakers (or headphones)

await _audioPlayer.setPlayingRoute(PlayingRoute.EARPIECE);

await _audioPlayer.setPlayingRoute(PlayingRoute.SPEAKERS);

Platforms iOS, Android, Web

dariocavada avatar Jul 12 '21 14:07 dariocavada

looking for same thing

arslan9380 avatar Jan 01 '22 10:01 arslan9380

Would be nice if this was automatic, at the moment it players though the device speaks making the plugin useless.

ollyde avatar Jul 05 '22 16:07 ollyde

I would like to know as well, as this was present in 0.19.1 as:

await audioPlayer.earpieceOrSpeakersToggle();

Cannot find any docs regarding removal/refactoring or whether it now somehow lives in AudioContext. Came across a few issues where people reported it did not work, is that why it was removed? Thank you.

tgrushka avatar Feb 28 '23 20:02 tgrushka

We did not remove it, we just made it more granular for each platform:

final audioContext = AudioContext(
    iOS: AudioContextIOS(
      options: [
        AVAudioSessionOptions.mixWithOthers,
      ],
    ),
    android: AudioContextAndroid(
      audioMode: AndroidAudioMode.inCommunication,
      isSpeakerphoneOn: false,
      usageType: AndroidUsageType.voiceCommunication,
    ),
  );
audioPlayer.setAudioContext(audioContext);

You can play around with the values, also in our example app.

Gustl22 avatar Mar 03 '23 12:03 Gustl22