iOS Question How to play audio in background?

mehdipass

Member
Hi,
When I press the home button and exit the app, streaming stops or I cannot hear.
How can I continue streaming in background and listen it from lock screen?
See this in stackoverflow
stackoverflow:
do {
    try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [.mixWithOthers, .allowAirPlay])
    print("Playback OK")
    try AVAudioSession.sharedInstance().setActive(true)
    print("Session is Active")
} catch {
    print(error)
}
 

MarcoRome

Expert
Licensed User
Longtime User
 
Upvote 1

mehdipass

Member
Hi,
I know this way.
But I like try other way.
How to convert following code to b4i?
AVAudioSession:
do {
    try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [.mixWithOthers, .allowAirPlay])
    print("Playback OK")
    try AVAudioSession.sharedInstance().setActive(true)
    print("Session is Active")
} catch {
    print(error)
}
 
Upvote 0
Top