HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS5,iOS6为什么AVAudioPlayer播放停止在屏幕锁定?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在为几个iOS应用程序使用AVAudioPlayer,它们都在屏幕锁定之后成功播放,直到我的iPad2上的iOS6(或iOS5),现在它们停止了.以下是我如何设置它,以前工作正常:

// Registers this class as the delegate of the audio session.
    [[AVAudioSession sharedInstance] setDelegate: self];

    // Use this code instead to allow the app sound to conTinue to play when the screen is locked.
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayBACk error: nil];

    UInt32 doSetProperty = 0;
    AudioSessionSetProperty ( kAudioSessionProperty_OverrideCategorymixWithOthers,sizeof (doSetProperty),&doSetProperty
                             );

    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    // Registers the audio route change listener callBACk function
    AudioSessionAddPropertyListener (
                                     kAudioSessionProperty_AudioRouteChange,audioRoutechangelistenerCallBACk,(__bridge void *)self
                                     );

// Activates the audio session.

    NSError *activationError = nil;
    [[AVAudioSession sharedInstance] setActive: YES error: &activationError];

    // Instantiates the AVAudioPlayer object,initializing it with the sound

    AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: medURL error: nil];
    self.appSoundPlayer = newPlayer;

    // "Preparing to play" attaches to the audio hardware and ensures that playBACk
    //      starts quickly when the user taps Play
    [appSoundPlayer prepareToPlay];
    [appSoundPlayer setVolume: 0.5];
    [appSoundPlayer setDelegate: self];

请注意,我将类别设置为AVAudioSessionCategoryPlayBACk,这是之前建议的修复程序.这是因为我升级到iOS6后无法正常工作 – 事实证明,iOS5也无法正常工作!

更新:我找到了一个基于这篇文章的答案:AVAudioPlayer stops playing on screen lock even though the category is AVAudioSessionCategoryPlayback

基本上我进入了目标的Info页面添加一个新的键“required BACkground modes”,为此我添加一个字符串类型值“App播放音频”.现在,在完全关闭屏幕之前,它会完全通过轨道.

解决方法

我根据这篇文章找到了一个似乎有效的答案:

AVAudioPlayer stops playing on screen lock even though the category is AVAudioSessionCategoryPlayback

基本上我进入了目标的Info页面添加一个新的键“required BACkground modes”,它会完全通过轨道.

大佬总结

以上是大佬教程为你收集整理的iOS5,iOS6为什么AVAudioPlayer播放停止在屏幕锁定?全部内容,希望文章能够帮你解决iOS5,iOS6为什么AVAudioPlayer播放停止在屏幕锁定?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。