2013-02-10 87 views
0

我有一个AVPlayer的问题,当我试图让播放器在背景上工作时,iPhone 6.0模拟器工作正常,但当应用程序转到背景时,真实设备上的声音消失了!AVPlayer背景问题

- (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; 
} 

回答