/Classes/AudioSessionDemo.h

http://github.com/kstenerud/ObjectAL-for-iPhone · C Header · 102 lines · 20 code · 6 blank · 76 comment · 0 complexity · bbad5f21d9132a2cf796f7f361aafae4 MD5 · raw file

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