0

我目前想知道如何

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

我可以通过对 a)使用AudioSession和对 b)使用 MPVolumeView 来分开。

现在我读到,我无法为 AudioSessions 设置音量,因为它们的音量是基于系统音量的,这在我的基础上很糟糕。在音量控制播放的同时停止播放 iPod 音乐更糟糕。

我注意到 runmeter(不想打广告,仅作为示例)例如有一个滑块,它控制应用程序的音量,而不管系统音量和/或 ipods 音量是多少。

所以我几乎可以将手机静音,将 ipod 放在中间并最大化应用程序音量,工作正常。

有什么方法/提示如何在不被苹果放弃的情况下完成这项工作?

有什么建议么?

谢谢。


编辑:感谢 badgrr 解决了这个问题,我的最终解决方案是通过使用 CocosDenshin:

appDelegate, applicationDidEnterBackground:

[[CDAudioManager sharedManager] setMode:kAMM_MediaPlayback];
[[CDAudioManager sharedManager] setResignBehavior:kAMRBDoNothing autoHandle:NO];

appDelegate, applicationWillEnterForeground: - 只是为了确定!

[[CDAudioManager sharedManager] setResignBehavior:kAMRBDoNothing autoHandle:NO];

播放时,我还需要知道声音文件何时完成,然后播放下一个,因为我不想同时构建句子。字。就像说“你好”然后说“世界”:

在初始化我的 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];
    }
}

希望它能帮助任何和我有同样问题的人!

4

1 回答 1

1

从评论转向回答,以便其他人更容易阅读。

看看CocosDenshion。它使用 OpenAL 来播放声音,并且可以通过不同界面控制的背景声音播放它们。如果需要,可以在不使用 Cocos2d 的情况下使用它。

为了防止音效停止 iPod 库播放,您需要使用以下行指定自定义音频会话:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL];
于 2011-04-15T09:33:45.717 回答