How do I keep music playing after the user presses the hold button on the iPhone?

Posted by Carlos Vargas on Stack Overflow See other posts from Stack Overflow or by Carlos Vargas
Published on 2010-03-26T05:35:10Z Indexed on 2010/03/26 13:03 UTC
Read the original article Hit count: 601

Filed under:
|

Hey guys how can I make an app keep playing an mp3 after pressed the hold/power button.

Here is the code I use for preparing the AVAudioPlayer:

- (void)PrepareAudio:(int)index
{

    NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@",[_Audio objectAtIndex:Game]] ofType:@"mp3"];
    NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
    MusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: newURL error: nil];
    [newURL release];

    [MusicPlayer setVolume: 1.5];
}

And this is the code when I press the button play:

- (IBAction)PushPlay: (id)sender
{
    if(!MusicPlayer.playing)
    [MusicPlayer play];
}

Best Regards

Carlos Vargas

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa-touch