即使应用程序进入后台,我也想播放音乐.我检查了所有stackoverflow链接,但没有一个工作.请帮助今天做.
我使用了以下代码: -
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Day At The Beach" ofType: @"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
NSError *error;
playerTemp = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
playerTemp.numberOfLoops = 0;
AudioSessionSetActive(true);
[playerTemp play];
Run Code Online (Sandbox Code Playgroud)