更改 iPhone 应用程序音量而不出现音量更改框(适用于日本的应用程序)
我正在制作一个具有拍照功能的增强现实应用程序。它使用我的自定义函数来创建 UIImage 来保存屏幕。根据日本法律,相机必须有快门噪音,这就是 iPhone 相机总是播放快门噪音的原因。到目前为止,我已经找到了一种即使 iPhone 静音时也可以播放声音的方法,但它仍然依赖于用户设置的音量。所以我找到了一种使用 MPMusicPlayerController 来控制应用程序音量的方法。这是可行的,但是当音量改变时,会弹出一个框,表明音量已改变。
这是我的代码,即使在静音时也能播放声音:
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),&sessionCategory);
我使用库 Finch 来播放声音(openAL 的轻型包装),然后使用 MPMusicPlayerController 在播放前调整音量。
appMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];
[appMusicPlayer setVolume:0.5f];
有人有这方面的经验或者为日本制作过这样的应用程序吗?我真是不知所措了。谢谢。
I am making an Augmented Reality application that has picture taking functionality. It uses a custom function of mine to create a UIImage to save the screen. By law in Japan, cameras must have a shutter noise, which is why the iPhone camera always plays it. So far I have found a way to play sounds even when the iPhone is muted but it still relies on the user set volume. So I found a way using MPMusicPlayerController to control the application volume. This works, but when the volume is changed a box pops up signaling that the volume was changed.
Here is my code to play sounds even when muted:
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),&sessionCategory);
I use the library Finch to play the sound (a light wrapper for openAL) and then MPMusicPlayerController to adjust the volume before play.
appMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];
[appMusicPlayer setVolume:0.5f];
Anyone have experience with this or have made apps like this for Japan? I'm really at a loss. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MPVolumeView
在可见时会遮挡浮动框,即使用户实际上看不到它。一些示例代码......
在改变音量以强制相机发出声音之前......
以及在声音之后,所以它看起来不像你弄乱了任何东西......
可能需要一些调整才能得到你想要的东西,但这应该是一个很好的起点。
此代码适用于
iOS 5.1
我不知道与旧版本的兼容性如何。
The
MPVolumeView
will, while visible, block the floating box, even if the user can't actually see it.Some sample code…
Before changing volume to force the camera to make sound…
And after sounds, so it doesn't look like you messed with anything…
It might take some tweaking to get what you want, but it should be a good starting point.
This code is for
iOS 5.1
I don't know what the compatibility is with older versions.