简体   繁体   English

允许用户继续在ios应用中听音乐

[英]Allow user to continue listening to their music in ios app

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. 如果完全相关,我正在使用AVAudioPlayer播放声音-背景音乐和声音效果。

I pulled this from my git history: 我从我的git历史中拉了这个:

  {  // 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM