سؤال

I've searched around for this but haven't found anything helpful thus far. In my app, any music that is already playing on the device is faded out to be replaced by my game's music.

I know from experience that this can be really annoying and can even be a reason to not play the game at all. How can I avoid this? More specifically, I would like the game's music and sound effects to be played if there is no music already being played by the user - otherwise the game music should be muted and the user's music should continue to play.

If at all relevant, I am using AVAudioPlayer to play my sounds - background music and sound effects.

هل كانت مفيدة؟

المحلول

I pulled this from my git history:

  {  // Set audio category to ambient - allows music to coexist with the application
     NSError *error;
     AVAudioSession *session = [AVAudioSession sharedInstance];
     [session setCategory: AVAudioSessionCategoryAmbient error: &error];
     if (error) {
        NSLog(@"setCategory failed %@",error);
     }
  }

Hope it helps.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top