views:

134

answers:

0

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