0
votes

I am developing an audio app. To play the various audio files I am using the just_audio package:

Just_Audio

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

2
I am also using the same package but I am not able to find an audio streaming position and complete audio duration... can you please help? - Chirag Chopra

2 Answers

1
votes

You can get the desired behaviour by setting your app's AVAudioSession category to playback via the audio_session package.

However, note that as of just_audio 0.4.0, this will actually be done for you by default. If you need to change the default, you can still do that via the audio_session package.

0
votes

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