【问题标题】:AVPlayer background issueAVPlayer后台问题
【发布时间】:2013-02-10 13:44:57
【问题描述】:

AVPlayer有问题,当我试图让播放器在后台工作时,iPhone 6.0模拟器工作正常,但当应用程序进入后台时,真机上的声音消失了!

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

【问题讨论】:

    标签: iphone ios background avplayer


    【解决方案1】:

    您还需要在 -info.plist 文件中包含以下内容:

    <key>UIBackgroundModes</key>
    <array>
        <string>audio</string>
    </array>
    

    http://developer.apple.com/library/ios/#qa/qa1668/_index.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多