我目前正在开发一款即使手机静音也需要播放短音频的应用。以下代码在手机未静音时播放音频,但在手机静音时不会播放音频,就像我想要的那样。
以下是代码:
// set playback settings
self.audioSession = [AVAudioSession sharedInstance];
[self.audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
AudioSessionSetActive(true);
UInt32 property = kAudioSessionProperty_OtherMixableAudioShouldDuck;
AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck, sizeof(property), &property);
OSStatus result = AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck, sizeof(property), &property);
if (result) {
NSLog(@"error seting property");
}
// set sound file settings
NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"baby_crying" ofType:@"mp3"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &soundId);
AudioServicesPlaySystemSound(soundId);
请告诉我此代码有什么问题。