1

I am trying to play a sound file when app is already in background AND stop current play music app if it is playing on iOS

Could you please tell me how can i do that

Many thanks,

William Tran.

2 Answers2

2

iOS will automatically pause other audio instances if your app begins one. Check out this thread: How to Play Audio in Background Swift?

will528
  • 21
  • 5
  • I am using Objective C. My script as below: AVAudioSession *avSession = [AVAudioSession sharedInstance]; NSError* __autoreleasing err = nil; [avSession setCategory:AVAudioSessionCategoryPlayback error:&err]; err = nil; [avSession setActive:YES error:&err]; self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soudnUrl error:NULL]; [audioPlayer prepareToPlay]; [audioPlayer play]; BUT IT DID NOT WORK – Nobita Kunz Mar 09 '18 at 06:12
0

i found out the reason for my issue: The operation couldn?t be completed. (OSStatus error 560557684.)

Because my app init and active an audio session when it is already in background that's why we could not do that.