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开发者_如何学Python when I press the button play:
- (IBAction)PushPlay: (id)sender
{
if(!MusicPlayer.playing)
[MusicPlayer play];
}
Best Regards
Carlos Vargas
If you are holding long enough to turn the device off, then there is no way. If you are pressing the button to lock the screen, the music can be played. Why don't you put some code up and let us see what you have tried. Hint: The answer lies within the Audio playback categories.
精彩评论