2013-02-10 89 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; 
} 

回答