I use AVAudioPlayerand NSFileHandlefor streaming audio. The basic idea is that I save streaming audio data to a device with a file system, and then use the file I just saved AVAudioPlayerto play. AVAudioPlayercan still play this file even in streaming mode.
I have UIButtonto start streaming / uploading. When the downloaded data is accumulated up to a certain number of bytes, it will be played AVAudioPlayer(the βplayβ method starts automatically AVAudioPlayer). My question is: I press the button to start streaming playback / downloading, and then press the iPhone home button very soon so that my application goes to the background. The download continues to run in the background, but the "play" method AVAudioPlayerreturns "NO", which means that the "play" method does not play audio.
I added the related code AVAudioSessionto my audio player initialization method:
- (id) initWithURL:(NSString *) downloadedMusicURL
{
if ((self = [super init]))
{
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
CFURLRef url = CFURLCreateWithFileSystemPath (NULL, (CFStringRef)downloadedMusicURL, kCFURLPOSIXPathStyle, FALSE);
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:CFBridgingRelease(url) error:nil];
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
}
return self;
}
info.plist "App play audio" " ". , "" - . ? .