大佬教程收集整理的这篇文章主要介绍了iOS5,iOS6为什么AVAudioPlayer播放停止在屏幕锁定?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
// 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播放音频”.现在,在完全关闭屏幕之前,它会完全通过轨道.
以上是大佬教程为你收集整理的iOS5,iOS6为什么AVAudioPlayer播放停止在屏幕锁定?全部内容,希望文章能够帮你解决iOS5,iOS6为什么AVAudioPlayer播放停止在屏幕锁定?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。