即使用户按下iPhone上的按钮HOME,我也想继续播放音乐。你能救我吗?
答案 0 :(得分:1)
引用this site。你会非常乐于助人。祝你好运
答案 1 :(得分:-1)
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"mysong" ofType:@"mp3"]];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; //This line is very important
[audioPlayer play];
[super viewDidLoad];