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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 09-02-2010, 03:00 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 8
Question MPMusicPlayerController with AVAudioPlayer

Hi All,

I am trying to play an in app audio with ipod the code I am using to play the audio file is:

Code:
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
		UInt32 doSetProperty = 1;
		AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty);
		[[AVAudioSession sharedInstance] setActive: YES error: nil];
		
		if(error)
		{
			NSLog(@"Some error happened");
		}
	
		NSString *path = [[NSBundle mainBundle] pathForResource:effect ofType:type];
		myPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
		myPlayer.delegate = self;
		myPlayer.numberOfLoops = -2;
		myPlayer.volume = 1.0f;
		[myPlayer play];
and to play the ipod music I am using
Code:
player = [MPMusicPlayerController iPodMusicPlayer];
My ipod plays fine until the audio starts playing but once the audio stops I am not able to get back to the ipod to play. I am using
Code:
NSString *value = [[NSUserDefaults standardUserDefaults] stringForKey:@"sound"];
	
	if([value compare:@"ON"] == NSOrderedSame && myPlayer != nil)
	{
		[myPlayer stop];
		[myPlayer release];
		myPlayer = nil;
	}
	
	NSError *error = nil;
	
	[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
	
	if(error)
	{
		NSLog(@"Some error happened");
	}
to stop the audio and then just call
Code:
[player play]
to play the ipod music but it does not play the music, it says the title to be null.

I would really appreciate if some one could help me with this.

Regards,
Ankur

Last edited by akki2010; 09-02-2010 at 12:14 PM.
akki2010 is offline   Reply With Quote
Old 09-02-2010, 03:19 AM   #2 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 81
Default

I'm using this lines to set up audio session:

Code:
[[AVAudioSession sharedInstance] setDelegate: self];
	[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
	[[AVAudioSession sharedInstance] setActive: YES error: nil];
And my in-app AVPlayer doesn't stop iPod.
__________________
iPhone 2G 8Gb 3.1.2 JB, 3G 16Gb 3.1.2 JB, 3GS 16 Gb 3.1.2 JB
MB5,1 C2D 2GHz 2GB RAM
Mac OS X 10.5.8
Jeepston is offline   Reply With Quote
Old 09-02-2010, 12:04 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 8
Default

Quote:
Originally Posted by Jeepston View Post
I'm using this lines to set up audio session:

Code:
[[AVAudioSession sharedInstance] setDelegate: self];
	[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
	[[AVAudioSession sharedInstance] setActive: YES error: nil];
And my in-app AVPlayer doesn't stop iPod.
that is just because you are using ambient category. I am using playback as I don't want my sound to be silent even when the phone ringer is turned to silent. but with playback category the ipod stops.
akki2010 is offline   Reply With Quote
Reply

Bookmarks

Tags
avaudioplayer, iphone, mpmusicplayercontroller

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: 237
15 members and 222 guests
ADY, Alsahir, dacapo, Dani77, Desert Diva, djohnson, F_Bryant, HemiMG, jansan, M@realobjects, MarkC, prchn4christ, smethorst, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

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