Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

audio - iOS: How do I detect if music is playing in any background music app?

I currently have my game correctly handling disabling its own BGM when music is playing in the built-in iPod app, but it does not detect when an app such as Pandora is playing music.

Currently, in my applicationDidBecomeActive method, I check [[MPMusicPlayerController iPodMusicPlayer] playbackState] to determine whether music is playing. What is the equivalent of this to check if an app like Pandora is playing audio in the background?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

AudioSessionGetProperty (as mentioned in jake_hetfield's answer) is deprecated as of iOS 7.

Instead, try this one-liner that uses isOtherAudioPlaying:

BOOL isOtherAudioPlaying = [[AVAudioSession sharedInstance] isOtherAudioPlaying];

Works on iOS 6+.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...