cocos2d-objc icon indicating copy to clipboard operation
cocos2d-objc copied to clipboard

AVAudioSessionCategoryAmbient does not work as expected

Open jonnyijapan opened this issue 11 years ago • 1 comments

Using cocos2d-swift that is bundled with SpriteBuilder 1.2.1.

I am trying to deal with background music of other apps (aka iPod music) in Cocos2D v3.x.

Preferrably, I wish my game wouldn't interfere at all with "iPod" music. Don't stop it if it's playing, don't stop ingame music or fx regardless if iPod music is playing or not. I have ingame volume controls for fx and bgm separately so the user should be able to listen to anything he needs that way.

I am doing this now, last thing in didFinishLaunching in app delegate, ie AFTER Cocos2D initialized:

[[OALAudioSession sharedInstance] setAudioSessionCategory:AVAudioSessionCategoryAmbient]; But I'm afraid it doesn't work well.

If we listen to iPod before we start the game, things seem to work ok.

But If we don't listen to iPod, and start the game, and in the game we wait until we can hear bgm and fx, then start iPod music (I use Apple's earphones to instantly start it without touching the iDevice), then bgm and fx will stop (error 1). Playing the game we notice that no fx are heard (error 2). When a bgm starts again in game, the iPod music is stopped (error 3) - note however that it's inconsistent because fx will never be heard again without relaunching the game (error 4). I can start iPod music again but then bgm will stop again (back on error 1). So basically at this point the user and the game can only fight over who will play music (user-iPod, game-bgm), and no fx will be heard, ever.

Regarding error 4: Whenever the game tries to play fx in this state, errors like these appear in console:

2014-10-01 12:41:59.763 egapyon[1848:353757] OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003) 2014-10-01 12:41:59.764 egapyon[1848:353757] OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing. 2014-10-01 12:41:59.765 egapyon[1848:353757] OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003) 2014-10-01 12:41:59.765 egapyon[1848:353757] OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing. 2014-10-01 12:41:59.767 egapyon[1848:353757] OAL Error: +[ALWrapper sourcef:parameter:value:]: Invalid Value (error code 0x0000a003) 2014-10-01 12:41:59.768 egapyon[1848:353757] OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing. 2014-10-01 12:41:59.769 egapyon[1848:353757] OAL Error: +[ALWrapper sourcef:parameter:value:]: Invalid Value (error code 0x0000a003) 2014-10-01 12:41:59.769 egapyon[1848:353757] OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing. 2014-10-01 12:41:59.770 egapyon[1848:353757] OAL Error: +[ALWrapper source3f:parameter:v1:v2:v3:]: Invalid Value (error code 0x0000a003) 2014-10-01 12:41:59.771 egapyon[1848:353757] OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing. 2014-10-01 12:41:59.773 egapyon[1848:353757] OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003) 2014-10-01 12:41:59.774 egapyon[1848:353757] OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing. 2014-10-01 12:41:59.774 egapyon[1848:353757] OAL Error: +[ALWrapper sourcePlay:]: Invalid Value (error code 0x0000a003) 2014-10-01 12:41:59.777 egapyon[1848:353757] OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing. 2014-10-01 12:42:01.808 egapyon[1848:353757] OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003) I play fx like this:

[[OALSimpleAudio sharedInstance] playEffect:@"somefile.m4a" volume:_volumeSfx pitch:PITCH pan:0 loop:NO]; Bgm like this:

[[OALSimpleAudio sharedInstance] playBg:@"somesong.mp3" loop:LOOP];

jonnyijapan avatar Oct 01 '14 03:10 jonnyijapan

Just faced same thing. Have you ever found a solution for that?

s1ddok avatar Jul 28 '16 15:07 s1ddok