即使在iphone按下HOME按钮后,我想继续播放音乐?

时间:2012-07-26 01:51:46

标签: ios iphone home-button

即使用户按下iPhone上的按钮HOME,我也想继续播放音乐。你能救我吗?

2 个答案:

答案 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];