0
嘿傢伙如何讓應用程序在按下按住/電源按鈕後繼續播放mp3。用戶按下iPhone上的保持按鈕後,如何保持音樂播放?
這裏是我使用的準備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];
}
當我按下按鈕播放這是代碼:
- (IBAction)PushPlay: (id)sender
{
if(!MusicPlayer.playing)
[MusicPlayer play];
}
問候
卡洛斯巴爾