1

我们正在使用下面的代码并通过应用程序多次调用此代码来播放按钮和应用程序声音。目前我们遇到的问题是设备上的音量控制不会改变内部应用程序的音量。我们可以将音量一直关闭,应用程序仍会播放声音。有没有办法检测硬件音量控制何时发生变化并相应地更新音量?我们不想更新滑块只是让音频会话响应新设置的音量。非常感谢您提前。

AudioSessionInitialize(NULL, NULL, NULL, self);
UInt32 category = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
                        sizeof(category),
                        &category);
AudioSessionSetActive(YES);

NSString *path = [NSString stringWithFormat:@"%@/%@.wav",
                                            [[NSBundle mainBundle] resourcePath],
                                            sound];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
4

1 回答 1

0

我已经在同一问题上进行了研发,您可以通过使用更改外部设备音量来更改音量滑块

MPMusicPlayerController *_musicController = [MPMusicPlayerController iPodMusicPlayer];

下面有几个链接,也许这些对你有帮助。

  1. http://stackoverflow.com/questions/9227435/changing-device-volume

  2. http://oleb.net/blog/2009/07/the-music-player-framework-in-the-iphone-sdk/

于 2012-04-24T06:55:22.340 回答