1
A
回答
4
一些快速示例代码,将做到这一点(当你的应用程序被激活或启动&不要忘了链接到AVFoundation框架从什么地方打电话):
#import <AVFoundation/AVAudioSession.h>
// ...
- (void)setupAudioSession
{
NSError* error = nil;
AVAudioSession* session = [AVAudioSession sharedInstance];
// see documentation for delegate methods you should handle
[session setDelegate:self];
// This category will duck and cancel background category, but can be configured
// later for mixing if you want (making it pretty versatile); see documentation
// on categories for other options
if(![session setCategory:AVAudioSessionCategoryPlayback error:&error]) {
// handle error
NSLog(@"Error setting audio category: %@, %@", error, [error userInfo]);
}
if(![session setActive:YES error:&error]) {
// handle error
NSLog(@"Error setting audio session as active: %@", error);
}
}
2
如果配置和激活某些音频会话类型在您的应用程序将播放声音(见苹果的音频会话参考),操作系统将淡出,从任何背景声音的应用程序当前正在使用的音频输出,让您的应用程序将有可用的资源。
相关问题
- 1. 当应用程序启动时,声音应该再次启动
- 2. 如何在打开应用程序时自动播放声音?
- 3. 在应用程序启动时播放声音
- 4. 如何在应用程序启动时停止后台任务?
- 5. 每次启动应用程序时播放声音
- 6. 我的ios应用程序启动时如何播放音频?
- 7. 如何在启动UIViewController *控制器时添加启动声音?
- 8. 声音使用ActionScript 3淡入/淡出
- 9. 如何在应用程序启动时自动启动Delayed_Job?
- 10. 如何在Windows启动时自动启动应用程序?
- 11. 如何在应用程序启动时“自动”启用GPS?
- 12. 如何在应用程序关闭时停止MediaPlayer的声音?
- 13. 如何在Android应用程序启动时启动服务?
- 14. 如何在u启动x时立即启动应用程序?
- 15. 如何在应用程序启动时启动Android服务?
- 16. 如何在启动设备时启动应用程序?
- 17. 如何在启动时启动plack应用程序
- 18. 如何在手机启动时启动Android应用程序?
- 19. 如何在启动电脑时启动Windows应用程序
- 20. 如何在启动时启动Firefox OS应用程序
- 21. 如何在Windows启动时优化WPF应用程序启动
- 22. 如何在启动应用程序主页时添加振动和铃声android
- 23. 在启动时启动应用程序
- 24. 在启动时启动应用程序
- 25. 如何在Ubuntu启动时禁用声音效果?
- 26. iOS - 任何应用程序启动时的调用方法
- 27. 如何在首次启动应用程序时访问任何方法
- 28. 如何淡入/淡出AngularJS应用程序中的文本?
- 29. 我的Java应用程序不能播放任何声音
- 30. 启动任何(或选定的)应用程序时启动我的活动
你好谢谢回答我得到这样的警告时,我用我们的代码警告:“AVAudioSession”可以不响应“:withError:-SETACTIVE”和应用程序不再在模拟器退出后2秒运行。方案? – 2010-10-06 18:34:48
@ Bobj-C:对不起,我是从记忆中打字。我将在代码示例中修复它,但该方法是setActive:error :. – 2010-10-06 19:00:25
警告是: 'AVAudioSession' 可能不响应 ':withError:-SETACTIVE'(![会议SETACTIVE:YES withError:&错误])这行,如果{ – 2010-10-06 19:13:43