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

后端 未结 4 756
南笙
南笙 2020-12-15 21:32

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 playi

4条回答
  •  余生分开走
    2020-12-15 21:56

    Check out this question

    Seems you can see if another audio is playing by checking the property kAudioSessionProperty_OtherAudioIsPlaying like this:

    UInt32 propertySize, audioIsAlreadyPlaying=0;
    propertySize = sizeof(UInt32);
    AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &propertySize, &audioIsAlreadyPlaying);
    

    A complement to this could be to ask the user if he/she wants to have the game music or the already playing sound/music.

提交回复
热议问题