更改iPhone应用程序音量,但不显示音量更改框(适用于日本的应用程序)
我正在制作一个具有拍照功能的增强现实应用程序。它使用我的一个自定义函数创建一个UIImage来保存屏幕。根据日本法律,相机必须有快门噪音,这就是为什么iPhone相机总是播放快门噪音的原因。到目前为止,我已经找到了一种即使在iPhone静音的情况下播放声音的方法,但它仍然依赖于用户设置的音量。所以我找到了一种使用MPMusicLayerController控制应用程序音量的方法。这是可行的,但当卷被更改时,会弹出一个框,表示卷已更改 以下是我的代码,可以在静音时播放声音:更改iPhone应用程序音量,但不显示音量更改框(适用于日本的应用程序),iphone,audio,openal,Iphone,Audio,Openal,我正在制作一个具有拍照功能的增强现实应用程序。它使用我的一个自定义函数创建一个UIImage来保存屏幕。根据日本法律,相机必须有快门噪音,这就是为什么iPhone相机总是播放快门噪音的原因。到目前为止,我已经找到了一种即使在iPhone静音的情况下播放声音的方法,但它仍然依赖于用户设置的音量。所以我找到了一种使用MPMusicLayerController控制应用程序音量的方法。这是可行的,但当卷被更改时,会弹出一个框,表示卷已更改 以下是我的代码,可以在静音时播放声音: AudioSe
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),&sessionCategory);
我使用库Finch播放声音(openAL的灯光包装),然后使用MPMusicLayerController在播放前调整音量
appMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];
[appMusicPlayer setVolume:0.5f];
有没有人有过这样的经验,或者为日本开发过这样的应用程序?我真是不知所措。谢谢。MPVolumeView将在可见时阻止浮动框,即使用户实际上看不到它 一些示例代码
// create/synthesize ivars for "MPVolumeView" and "UIView" (both are necessary)
// I called them "mpVolumeView" and "mpVolumeViewParentView" respectively
// the UIView containing the MPVolumeView can have a frame of (0,0,1,1)
// this way, the user never sees the slider, but it still works normally
- (void)viewDidLoad {
...
// with this, only the slider is visible
mpVolumeViewParentView.backgroundColor = [UIColor clearColor];
// initialize the volume slider (link the parent view in IB, or init here)
mpVolumeView = [[MPVolumeView alloc] initWithFrame:
mpVolumeViewParentView.bounds];
// since it's a programmatic init, the subview must be added like so
[mpVolumeViewParentView addSubview:mpVolumeView];
// allows the floating box to appear without destroying mpVolumeView
mpVolumeView.hidden = YES; // or [mpVolume setHidden:YES]; if you prefer
...
}
在更改音量以强制相机发出声音之前
mpVolumeView.hidden = NO; // view visible, box doesn't appear
而且在声音之后,所以看起来你不会弄乱任何事情
mpVolumeView.hidden = YES; // view hidden, box appears
可能需要一些调整才能得到你想要的,但这应该是一个很好的起点
此代码适用于iOS 5.1
我不知道与旧版本的兼容性是什么