0
votes

I have a radio player embedded in my Xamarin.iOS app, but when the screen locks the audio stops playing. Per this thread https://forums.xamarin.com/discussion/36651/play-audio-in-background-for-iphone I tried adding this into my AppDelegate's FinishedLaunching method but it didn't work:

var currentSession = AVAudioSession.SharedInstance(); currentSession.SetCategory(AVAudioSessionCategory.Playback, AVAudioSessionCategoryOptions.MixWithOthers); currentSession.SetActive(true);

AVAudioSessionCategory.Playback plays audio even if the phone is in silent mode. (This works). AVAudioSessionCategoryOptions.MixWithOthers allows to play multiple sounds simultaneously from several apps. (I haven't tested this but it's not relevant to my issue).

currentSession.SetActive(true) should be allowing audio in the background while the screen is locked but it doesn't work.

Any ideas?

1

1 Answers

1
votes

You need to register your app for background audio. See: https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/registering-applications-to-run-in-background

Applications can be registered by setting the Required Background Modes property in the application's Info.plist. An application can register in as many categories as it requires

So open your Info.plist file and select the following options:

VS (PC):

enter image description here

VS (Mac):

enter image description here