2011-11-04 60 views
0

您好我已经把我的应用程序的音频会议ambientsound, 当我推出了应用程序的拳头时,她刚刚杀死音乐时播放音乐。 我不希望这种事情发生。 有任何其他的方式来设置这个?应用程序关闭推出

+1

她不好那样! –

+0

我的回答有帮助吗? – Oliver

+0

我没有尝试,但 –

回答

2

试试这个:

激活音频会话:

OSStatus activationResult = NULL; 
result = AudioSessionSetActive (true); 

测试,如果其他音频播放

UInt32 otherAudioIsPlaying;         // 1 
UInt32 propertySize = sizeof (otherAudioIsPlaying); 

AudioSessionGetProperty (         // 2 
    kAudioSessionProperty_OtherAudioIsPlaying, 
    &propertySize, 
    &otherAudioIsPlaying 
); 

if (otherAudioIsPlaying) {         // 3 
    [[AVAudioSession sharedInstance] 
        setCategory: AVAudioSessionCategoryAmbient 
          error: nil]; 
} else { 
    [[AVAudioSession sharedInstance] 
        setCategory: AVAudioSessionCategorySoloAmbient 
          error: nil]; 
} 

如果是,允许混合

OSStatus propertySetError = 0; 
UInt32 allowMixing = true; 
propertySetError = AudioSessionSetProperty (
         kAudioSessionProperty_OverrideCategoryMixWithOthers, // 1 
         sizeof (allowMixing),         // 2 
         &allowMixing           // 3 
        ); 

来源:http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Cookbook/Cookbook.html