开发者

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

开发者 https://www.devze.com 2022-12-24 13:25 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消