1

我目前正在开发一个应用程序,即使手机静音也需要播放短音频。以下代码在手机未静音时播放音频,但在手机静音时不会播放音频,就像我想要的那样。

这是代码:

// 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);

请让我知道这段代码有什么问题。

4

0 回答 0