jason white
jason white

Reputation: 711

iOS Coco2D playing 2 background sounds

Can Coco2D playing 2 background sounds?

[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"sound1.caf" loop:YES];
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"sound2.caf" loop:YES];

Can sound2 be set to half of the volume and sound1 be the dominant?

Upvotes: 1

Views: 245

Answers (2)

jptsetung
jptsetung

Reputation: 9156

From Steve Oldmeadow, author of CocosDenshion, the audio engined shipped with cocos2d.

There is a single AVAudioPlayer that plays background music so you can only have one background music file loaded at a time, if you need something more sophisticated then you have to roll your own solution.

Interesting links

http://www.cocos2d-iphone.org/forum/topic/3074

Cocos2d play 2 different background music files or loop playEffect

Upvotes: 0

Mazyod
Mazyod

Reputation: 22559

It is highly discouraged to play two BGM (Background Music) at the same time. Because of the iPhone's hardware architecture, it has only one hardware sound decoder to play compressed music files.

With that said, your sounds seem to be in caf format, which is uncompressed, and thus easy to play using playEffect:. You can play as many effects as you want at the same time, without worrying about performance that much.

NOTE: The playEffect: method should only be used with uncompressed audio, such as caf, aif, ... etc.

Upvotes: 1

Related Questions