I have a problem with AVPlayer
, when I tried to make the player working on the background, the iPhone 6.0 simulator works fine, but the sound on the real device disappears when the application goes to the background!
- (IBAction)RayaFM {
NSURL *URLA = [NSURL URLWithString:@"http://live.raya.fm:8032/;stream.mp3"];
self.player = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWithURL:URLA]];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
[self.player play];
newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
if (newTaskId != bgTaskId != UIBackgroundTaskInvalid)
[[UIApplication sharedApplication] endBackgroundTask: bgTaskId];
bgTaskId = newTaskId;
}