2009-10-02 3 views
7

AVAudioPlayerを使用してアプリケーションでサウンドを再生しますが、サウンド再生時にiPodをオフにします。AVAudioPlayerはiPodをオフにします - 回避するには?

これを防ぐ方法はありますか?私は音量をコントロールすることができないので、System Soundsを使用したくありません。

ありがとうございました。

答えて

15

これはあなたのために働く必要があるドキュメントから

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil]; 
UInt32 doSetProperty = 1; 
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty); 
[[AVAudioSession sharedInstance] setActive: YES error: nil]; 

(私のアンビエンスアプリから撮影):

kAudioSessionProperty_OverrideCategoryMixWithOthers Changes the mixing behavior of the kAudioSessionCategory_MediaPlayback and kAudioSessionCategory_PlayAndRecord audio session categories. Setting this property to TRUE (any nonzero value) allows mixing of iPod audio with application audio. Other aspects of these categories, such as their Ring/Silent switch behavior, are not affected.

This property has value of FALSE (0) by default. When the audio session category changes, such as during an interruption, the value of this property reverts to FALSE. To regain mixing behavior you must then re-set this property.

Always check to see if setting this property succeeds or fails, and react appropriately; behavior may change in future releases of iPhone OS.

Available in iPhone OS 3.0 and later.

Declared in AudioServices.h.

+0

おかげでconeybeare :) –

+1

は、アプリのデリゲートでこれを入れてください。私のためにうまくいった。楽しんで、仲間のgooglers;) –

+2

すごい!ありがとう!私のような初心者の方に:#import を実行し、AudioToolboxフレームワークをリンクする必要があります。 XCode 4.2でこれを行う方法については、こちらをご覧ください:http://stackoverflow.com/questions/3352664/how-to-add-existing-frameworks-in-xcode-4 –

関連する問題