2009-10-02 13 views
7

मैं अपने ऐप में ध्वनि चलाने के लिए AVAudioPlayer का उपयोग करता हूं, लेकिन ध्वनि चलाने पर यह आईपॉड बंद कर देता है।AVAudioPlayer आईपॉड बंद कर देता है - कैसे काम करना है?

क्या इसे रोकने का कोई तरीका है? मैं सिस्टम ध्वनि का उपयोग नहीं करना चाहता क्योंकि मैं उनकी मात्रा को नियंत्रित नहीं कर सकता।

आपकी मदद के लिए धन्यवाद।

उत्तर

15

यह आप के लिए काम करना चाहिए (मेरे Ambiance एप्लिकेशन से लिया)

[[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 और ऑडियोटूलबॉक्स ढांचे को लिंक करने की आवश्यकता है। XCode 4.2 में ऐसा करने के तरीके के बारे में सहायता के लिए, यहां देखें: http://stackoverflow.com/questions/3352664/how-to-add-existing-frameworks-in-xcode-4 –

संबंधित मुद्दे

 संबंधित मुद्दे