我正在使用AVAudioPlayer流式播放音乐文件,如果我使用nib文件,它在后台播放得很好,但当我使用故事板尝试相同的代码时,音乐播放停止。我不明白为什么当我使用故事板的时候它会在后台停止播放。
我正在使用下面的代码
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[audioPlayer setVolume:0.1];
[audioPlayer play];可以帮助我使用故事板在后台播放它。提前谢谢。
发布于 2014-05-04 17:38:59
让我们试一试:
@implementation YourViewController
{
AVAudioPlayer *audioPlayer;
}
// if your are using ARC, after exiting this method, system will kill your audioPlayer. This is the reason why you can not play the music.
// in your method:
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];https://stackoverflow.com/questions/23452779
复制相似问题