Checklist
Current bug behaviour
During player playback, I want to dynamically switch from speaker to earphone to play, but there is no effect. After switching, the music currently playing will be completely sounded (there was a sound before switching)
Expected behaviour
Dynamically switch from speaker to earphone to playback, and you can hear the current music from earphone normally
Steps to reproduce
No response
Code sample
AudioContext get speakerOnAudioContext => AudioContext(
iOS: AudioContextIOS(
/// not silenced
category: AVAudioSessionCategory.playback,
options: const {
AVAudioSessionOptions.mixWithOthers,
},
),
android: const AudioContextAndroid(
isSpeakerphoneOn: true,
stayAwake: true,
contentType: AndroidContentType.unknown,
usageType: AndroidUsageType.notificationRingtone,
audioFocus: AndroidAudioFocus.gain,
),
);
AudioContext get speakerOffAudioContext => AudioContext(
iOS: AudioContextIOS(
/// not silenced
category: AVAudioSessionCategory.playAndRecord,
options: const {
AVAudioSessionOptions.mixWithOthers,
},
),
android: const AudioContextAndroid(
isSpeakerphoneOn: false,
stayAwake: true,
contentType: AndroidContentType.unknown,
usageType: AndroidUsageType.notificationRingtone,
audioFocus: AndroidAudioFocus.gain,
),
);
// init
AudioPlayer.global.setAudioContext(speakerOnAudioContext);
// play
audioPlayer.play(AssetSource(sourcePath));
// switch:then i switch by button:
final targetContext = currentAudioRoute == speaker
? speakerOnAudioContext
: speakerOffAudioContext;
audioPlayer.setAudioContext(targetContext)
Affected platforms
Android, iOS
Platform details
No response
AudioPlayers Version
6.5.1
Build mode
debug
Audio Files/URLs/Sources
No response
Screenshots
No response
Logs
Full Logs
my full logs or a link to a gist
Flutter doctor:
Output of: flutter doctor -v
Related issues / more information
No response
Working on PR
no way
Checklist
Current bug behaviour
During player playback, I want to dynamically switch from speaker to earphone to play, but there is no effect. After switching, the music currently playing will be completely sounded (there was a sound before switching)
Expected behaviour
Dynamically switch from speaker to earphone to playback, and you can hear the current music from earphone normally
Steps to reproduce
No response
Code sample
Affected platforms
Android, iOS
Platform details
No response
AudioPlayers Version
6.5.1
Build mode
debug
Audio Files/URLs/Sources
No response
Screenshots
No response
Logs
Full Logs
Flutter doctor:
Related issues / more information
No response
Working on PR
no way