2009-10-02 13 views
7

Używam AVAudioPlayer do odtwarzania dźwięków w mojej aplikacji, ale wyłącza iPoda, gdy odtwarzany jest dźwięk.AVAudioPlayer wyłącza iPoda - jak obejść?

Czy istnieje sposób, aby temu zapobiec? Nie chcę używać dźwięków systemowych, ponieważ nie mogę kontrolować ich głośności.

Dzięki za pomoc.

Odpowiedz

15

To powinno działać dla ciebie (wzięte z mojego Ambiance aplikacji)

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

Od docs:

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

Dzięki coneybeare :) –

+1

umieścić to w app delegata. Sprawdziło się dla mnie dobrze. Baw się dobrze, inni googlersi;) –

+2

Ogromny! Dzięki! Dla innych początkujących, takich jak ja: aby uzyskać połączenie, musisz wykonać #import i połączyć framework AudioToolbox. Aby uzyskać pomoc, jak to zrobić w XCode 4.2, zajrzyj tutaj: http://stackoverflow.com/questions/3352664/how-to-add-existing-frameworks-in-xcode-4 –

Powiązane problemy