I am developing an audio app. To play the various audio files I am using the just_audio package:
It works fine on Android phones, but with iPhones when the phone is set to silent mode it is not playing any sound. Is there anyway to fix this that anyone has come across?
My code set up is very simple:
I declare the player:
final _player = AudioPlayer();
Set the url:
setAudioUrl(widget.mediaItem.itemUrl);
And play:
await _player.play();
Any help would be greatly appreciated.
Thanks
Carson
I added the following to my /ios/Runner/AppDelegate.swift file (inside didFinishLaunchingWithOptions) which fixed the issue - for anyone else interested.
do {
if #available(iOS 10.0, *){
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault)
try AVAudioSession.sharedInstance().setActive(true)
}
} catch {
print(error)
}