jeudi 30 juin 2016

Can you programmatically determine what app has the audio session on iPhone?


Is it possible to programmatically determine which app has the audio in iOS? My understanding is that the last app to play audio has the session regardless of whether it is still playing audio, or not.

Note: I know the following code is possible (from here: Detecting active AVAudioSessions on iOS device), but it only tells me that audio is playing in another app, not if another app has the audio session but isn't playing:

// query if other audio is playing
BOOL isPlayingWithOthers = [[AVAudioSession sharedInstance] isOtherAudioPlaying];
// test it with...
(isPlayingWithOthers) ? NSLog(@"other audio is playing") : NSLog(@"no other audio is playing");

My app can play background audio and supports BT low energy. It can therefore be in the background and play audio. However, if another app has taken the audio session (for example, Spotify) I'd like to know so that I can do something about it - such as by sending a message to the display of my BTLE device to ask the user to foreground my app.

Not elegant but I'm not sure there's much else I can do?


Aucun commentaire:

Enregistrer un commentaire