0

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!

thedanielhanke
  • 730
  • 1
  • 6
  • 22
  • Are you able to use OpenAL for your sounds? That would allow you to control the sound volume separately. – badgerr Apr 15 '11 at 08:23
  • badgerr, thanks for this hint! i tried to look it up a bit, did not clearly get a note wether i can play openAL in background as well? i added this information to my question, i just forgott to name this major part.. – thedanielhanke Apr 15 '11 at 09:15
  • Have a look at [CocosDenshion](http://www.cocos2d-iphone.org/wiki/doku.php/cocosdenshion:faq). It uses OpenAL for sounds, and can play them over background sounds controlled with a different interface – badgerr Apr 15 '11 at 09:20
  • okay i will denshion another try, maybe i was to quick with it! thanks badgerr! thanks a lot! – thedanielhanke Apr 15 '11 at 09:31

1 Answers1

1

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:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL];
badgerr
  • 7,802
  • 2
  • 28
  • 43
  • badgerr, seems like you have some exp. with it. now since my time is running out, (vacations trip, flight in 4 hrs), i need to finish this thing, actually i just cannot figure out in CDSoundEngine where to tell not to pause ipod. it does by using alloc/init, loadBuffer w/ filepath and playSound. did not find a documentation hint eighter. any clue? – thedanielhanke Apr 15 '11 at 09:56
  • Yes, I have used it in iPhone games playing sound effects and background music at the same time. – badgerr Apr 15 '11 at 09:58
  • backgroundmusic from the same app, not ipod i guess? – thedanielhanke Apr 15 '11 at 10:20
  • CocosDenshion + iPod needs a custom Audio Session. Put this somewhere near the start of your app: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL]; – badgerr Apr 15 '11 at 10:29
  • well that works, but now since its ambient, its quite silent! any clue how to get rid of this silenting? for systemSoundsession there was a mixing-property for example. the reason is, the user should be able to set the volume of it to its wishes. not to apples ;) – thedanielhanke Apr 15 '11 at 10:49
  • MPMusicPlayerController volume also sets loudness of ipod - thats not the goal - and indead my problem. the "(only)" in my question was based on having application-only-sound-settings, sorry if i was unclear – thedanielhanke Apr 15 '11 at 10:56
  • I'm not sure what you mean by this. You can set the MPMusicPlayerController volume with the volume property, and CocosDenshion SimpleAudioEngine has a similar effectsVolume property. – badgerr Apr 15 '11 at 10:57
  • Ahh I see. Well, I *think* you can have isolated music player settings by using +[MPMusicPlayerController applicationMusicPlayer] instead of +[MPMusicPlayerController iPodMusicPlayer] – badgerr Apr 15 '11 at 10:58
  • for any reason, i never figured out a difference between [MPMusicPlayerController applicationMusicPlayer] and iPodMusicPlayer, changing first also changes 2nd. thats why i am confused! :) – thedanielhanke Apr 15 '11 at 11:04
  • Maybe that's just the way it is for volume. The difference between the two is that changing tracks in applicationMusicPlayer does not affect iPod track selection. Also, when applicationMusicPlayer app is sent to background, its music stops, where iPodMusicPlayer will continue even after the app quits, unless it is explicitly stopped first. – badgerr Apr 15 '11 at 11:14
  • ah horray now for any reason it works, looks like i had a 2nd soundsession anywhere ... thank you – thedanielhanke Apr 15 '11 at 11:22