/Classes/AudioSessionDemo.h
C Header | 102 lines | 20 code | 6 blank | 76 comment | 0 complexity | bbad5f21d9132a2cf796f7f361aafae4 MD5 | raw file
Possible License(s): Apache-2.0
1// 2// AudioSessionDemo.h 3// ObjectAL 4// 5// Created by Karl Stenerud. 6// 7 8#import "cocos2d.h" 9#import "LampButton.h" 10#import "ObjectAL.h" 11 12/** 13 * This is mainly a test scene to try out various combinations of 14 * audio session settings. 15 * 16 * Generally, you should set up the audio session settings ONCE, and then 17 * use your program. Changing around settings after playing sounds or using 18 * iPod playback can cause problems in certain situations, resulting in 19 * no sound being output, error messages (especially in OpenAL), and even 20 * crashes. You can try changing around live settings in this demo to see 21 * what works and what doesn't, but there's no guarantee of consistency in 22 * Apple's already obscure implementation. 23 * 24 * 25 * The buttons are as follows: 26 * 27 * Session Active: Controls the audio session's state (active or not). 28 * Once OpenAL initializes, you can't deactivate the session without first 29 * disabling the current OpenAL context. 30 * 31 * Suspended: Controls suspending the sound system. This works every time 32 * because it first suspends OpenAL and AVAudioPlayer. 33 * You need to suspend and resume for some of the audio session settings to 34 * take effect. 35 * 36 * Allow iPod: When enabled, the application will use software decoding 37 * (except in a special case where "Use Hardware" is enabled, see below). 38 * This allows it to coexist with iPod music playing. 39 * 40 * iPod Ducking: When enabled, causes any iPod style music to decrease 41 * in volume while the audio session is active. 42 * Note: This only seems to work when "Silent Switch" is disabled. 43 * 44 * Silent Switch: Determines whether the app goes silent when the silent 45 * switch is turned on. Also prevents sound playback from stopping when 46 * the screen locks. 47 * 48 * Use Hardware: When enabled, the sound system will attempt to use the 49 * hardware decoder if available (no iPod music playing). If the hardware 50 * is not being used, the sound system will take it, preventing iPod playback. 51 * If the hardware is being used, the sound system will use software decoding. 52 * 53 * The "Play/Stop" and "Paused" buttons control looping OpenAL and AVAudioPlayer 54 * playback. 55 * 56 * 57 * BUGS: 58 * 59 * There are cases where iOS behaves weirdly, as can be demonstrated here. 60 * 61 * Case 1: iPod ducking fails to unduck. 62 * 63 * Steps to reproduce: 64 * - iPod Ducking: ON 65 * - Silent Switch: OFF 66 * - Switch to iPod player and start playing. 67 * - Suspending/unsuspending causes iPod to duck or unduck. 68 * - Playing BOTH an ALSource and an AudioTrack, then suspending, will prevent 69 * iPod from unducking. 70 * 71 * 72 * Case 2: iOS fails to clear interrupt. 73 * 74 * Steps to reproduce: 75 * - Turn off "Allow iPod", "Silent Switch", and "iPod Ducking". 76 * - Switch to the mini ipod player and start it playing. This causes an interrupt. 77 * - Stop music in mini ipod player and return to the app. This does NOT clear the interrupt. 78 * System is still interrupted and will not play sounds. 79 * To clear the interrupt, background the app and then open it again. 80 * OALAudioSupport has a method "forceEndInterruption" to help with these sorts of situations. 81 */ 82@interface AudioSessionDemo : CCLayer 83{ 84 ALSource* source; 85 ALBuffer* buffer; 86 OALAudioTrack* track; 87 88 LampButton* allowIpodButton; 89 LampButton* ipodDuckingButton; 90 LampButton* honorSilentSwitchButton; 91 LampButton* useHardwareButton; 92 LampButton* sessionActiveButton; 93 LampButton* suspendedButton; 94 95 LampButton* playStopSource; 96 LampButton* pauseSource; 97 98 LampButton* playStopTrack; 99 LampButton* pauseTrack; 100} 101 102@end