iPhone 设置播放声音的音量(仅适用于应用程序)
我目前想知道如何
a) Play a sound next to iPod/Other music sources
b) beeing able to control the volume of that played sound (only)
c) **important** both combined!!
d) all of it also on background/mt
通过使用 AudioSession 来实现 a) 并使用 MPVolumeView 来实现 b) 的分离。
现在我读到,我无法设置 AudioSessions 的音量,因为它们的音量基于系统音量,这对我来说很糟糕。在进行音量控制播放时停止播放 iPod 音乐更糟糕。
我注意到 runmeter(不想做广告,只是作为一个例子)有一个滑块,可以控制应用程序的音量,无论系统音量和/或 iPod 音量是多少。
所以我几乎可以将手机静音,将 iPod 置于中间并将应用程序音量最大化,工作正常。
有什么方法/提示如何完成此操作而不被苹果删除?
有什么建议吗?
谢谢。
编辑:感谢 badgrr 解决了这个问题,我的最终解决方案是通过使用 CocosDenshin:
appDelegate, applicationDidEnterBackground:
[[CDAudioManager sharedManager] setMode:kAMM_MediaPlayback];
[[CDAudioManager sharedManager] setResignBehavior:kAMRBDoNothing autoHandle:NO];
appDelegate, applicationWillEnterForeground: - 只是为了确定!
[[CDAudioManager sharedManager] setResignBehavior:kAMRBDoNothing autoHandle:NO];
播放时,我还需要知道声音文件何时完成,以便播放下一个,因为我不想同时混合构建句子。字。就像说“Hello”然后“world”:
在初始化我的Soundplayer时:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&err];
[[CDAudioManager sharedManager] setMode:kAMM_MediaPlayback];
soundEngine = [[CDAudioManager sharedManager] audioSourceForChannel:kASC_Right];
soundEngine.delegate = self; // ensure to implement <CDLongAudioSourceDelegate>
播放声音:
- (void)playSound:(NSString *)soundFile
{
[soundEngine load:[NSString stringWithFormat:@"%@.caf",soundFile]];
[soundEngine play];
....
}
并在当前停止后播放下一个(我的audioQueue是一个NSMutableDictionay)
- (void) cdAudioSourceDidFinishPlaying:(CDLongAudioSource *) audioSource
{
if ([self.audioQueue count] > 0)
{
[self.audioQueue removeObjectAtIndex:0];
}
if ( [self.audioQueue count] > 0 )
{
NSString *file = [self.audioQueue objectAtIndex:0];
[self playSound:file];
}
else
{
//NSLog(@"SoundsManager::cdAudio.. Done, queue empty");
[self resumeIPod];
}
}
希望它可以帮助任何与我有同样麻烦的人!
i currently wonder how to
a) Play a sound next to iPod/Other music sources
b) beeing able to control the volume of that played sound (only)
c) **important** both combined!!
d) all of it also on background/mt
I am able to do both sepperate by using AudioSession for a) and MPVolumeView for b).
now i read, that i cannot set volume for AudioSessions, since their volume is based on systems volume, which is bad in my base. Stopping the iPod music while having volume-controled playback is even worse.
i noticed that runmeter (dont want to ad, just as an example) for example has a slider, that controls the apps volume regardless of what the systems volume and/or ipods volume is.
so i can nearly mute the phone, middle the ipod and maximize the apps-volume, working fine.
is there any way/hint how to get this done w/o getting dropped by apple?
any suggestions?
Thanks.
EDIT: thanks to badgrr for solving this, my final solution was, via using CocosDenshin:
appDelegate, applicationDidEnterBackground:
[[CDAudioManager sharedManager] setMode:kAMM_MediaPlayback];
[[CDAudioManager sharedManager] setResignBehavior:kAMRBDoNothing autoHandle:NO];
appDelegate, applicationWillEnterForeground: - just to get sure!
[[CDAudioManager sharedManager] setResignBehavior:kAMRBDoNothing autoHandle:NO];
playback, i also needed to know when a soundfile was done, to play the next, since i do not want to have built sentences in a mix of simult. words. like saying "Hello" then "world":
on initializing my Soundplayer:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&err];
[[CDAudioManager sharedManager] setMode:kAMM_MediaPlayback];
soundEngine = [[CDAudioManager sharedManager] audioSourceForChannel:kASC_Right];
soundEngine.delegate = self; // ensure to implement <CDLongAudioSourceDelegate>
playing sounds:
- (void)playSound:(NSString *)soundFile
{
[soundEngine load:[NSString stringWithFormat:@"%@.caf",soundFile]];
[soundEngine play];
....
}
and playing the next one, after current stopps (my audioQueue is an NSMutableDictionay)
- (void) cdAudioSourceDidFinishPlaying:(CDLongAudioSource *) audioSource
{
if ([self.audioQueue count] > 0)
{
[self.audioQueue removeObjectAtIndex:0];
}
if ( [self.audioQueue count] > 0 )
{
NSString *file = [self.audioQueue objectAtIndex:0];
[self playSound:file];
}
else
{
//NSLog(@"SoundsManager::cdAudio.. Done, queue empty");
[self resumeIPod];
}
}
hope it helps out anybody having same trouble as i do!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从评论转向答案,以便其他人更容易阅读。
看看 CocosDenshion。它使用 OpenAL 来播放声音,并且可以通过不同界面控制的背景声音来播放它们。如果需要,可以在不使用 Cocos2d 的情况下使用它。
为了防止声音效果停止 iPod 库播放,您需要使用以下行指定自定义音频会话:
Moving from comments to answer so it's a bit easier for others to read.
Have a look at CocosDenshion. It uses OpenAL for sounds, and can play them over background sounds controlled with a different interface. It is possible to use it without having to use Cocos2d, if required.
In order to prevent the sound effects stopping iPod library playback, you need to specify a custom audio session with the following line: