Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-20-2010, 12:34 PM   #1 (permalink)
Registered Member
 
god0fgod's Avatar
 
Join Date: Jul 2010
Posts: 278
god0fgod is on a distinguished road
Default AVAudioSession not working as described by Apple

I've found a bug which is probably Apple's fault. I need a way around it.

My game has 3 background songs. I would like the game to set the background music to off when there is ipod music playing, else it will play the last played piece of music. When the muser changes the music with the ipod music on, the ipod music should go away and the background music plays. The problem is, the *second time* I try to do this (Changing the music from ipod to in-game) the first song will play but the other two will not.

This is stupid behaviour and it wont work any way I try to solve the problem. Here's my current code....

In the drawRect loop:

Code:
//Music toggle
						if(music_active == 0){
							[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:NULL];
							[[AVAudioSession sharedInstance] setActive:YES error:NULL];
							[background_music play];
							music_active++;
						}else if(music_active == 1){
							[background_music pause];
							[background_musicB play];
							music_active++;
						}else if(music_active == 2){
							[background_musicB pause];
							[background_musicC play];
							music_active++;
						}else{
							[background_musicC pause];
							music_active = 0;
						}
In the startAnimation method:

Code:
UInt32 size,result;
		size = sizeof(result);
		AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying,&size,&result);
		if(!result){
			[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:NULL];
			[[AVAudioSession sharedInstance]  setActive:YES error:NULL];
			[background_music prepareToPlay];
			[background_musicB prepareToPlay];
			[background_musicC prepareToPlay];
			if(music_active == 1){
				[background_music play];
			}else if(music_active == 2){
				[background_musicB play];
			}else if(music_active == 3){
				[background_musicC play];
			}
		}else{
			music_active = 0;
		}
In the stopAnimation method:

Code:
[background_music stop];
		[background_musicB stop];
		[background_musicC stop];
		[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL];
		[ [AVAudioSession sharedInstance] setActive:NO error:NULL];
In the initWithCoder method:

Code:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:NULL];
This method also loads the sound files and sets the number of loops to -1. It uses AVAudioPlayer, of-course.

This problem is annoying me because I didn't find it in my testing before I submitted the game to Apple. I need to get it fixed for an immediate update when the game is approved or to re-submit if it is rejected. I don't see what I'm doing wrong. I'm following the documentation perfectly. It must be Apple's fault unless I'm missing something?

Thank you for any help.
__________________
god0fgod is offline   Reply With Quote
Old 10-21-2010, 12:05 PM   #2 (permalink)
Registered Member
 
god0fgod's Avatar
 
Join Date: Jul 2010
Posts: 278
god0fgod is on a distinguished road
Default

Basically, startAnimation is being called and result will be false because I wont play anything at first. Then stopAnimation is called before startAnimation is called again with result as true. I then switch the music which runs through the code in the drawRect method. It works. stopAnimation is called again before startAnimation is called with result as true for the second time. Switching the music then fails
__________________
god0fgod is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 328
8 members and 320 guests
condor304, Desert Diva, dre, hain, mottdog, oceanlablight, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:10 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0