Avaudiosessioncategoryambient or kaudiosessioncategory_ambientsound--are used for non-voice-based applications, and apps that use this category will be muted with the mute key and the screen off. It does not stop other apps from playing sound, and can play sounds with other apps such as Ipod,safari. Note: The category cannot play sound avaudiosessioncategorysoloambient or kaudiosessioncategory_soloambientsound--in the background Similar to the avaudiosessioncategoryambient, the difference is that it stops other apps from playing sounds. This category is the default category. The category cannot play sound avaudiosessioncategoryplayback or kaudiosessioncategory_mediaplayback--in the background for voice-based applications, Apps that use this category do not mute with the mute key and the screen off. You can play sound Avaudiosessioncategoryrecord or Kaudiosessioncategory_recordaudio in the background ——— for apps that need to be recorded, and after you set that category, in addition to the call tones Other system sounds other than alarm or calendar reminders will not be played. This category only provides a simple recording function. Avaudiosessioncategoryplayandrecord or kaudiosessioncategory_playandrecord--for applications that need to play both sound and recording Voice chat apps (such as) should use this category. This category provides recording and playback functions. If your app needs an iphone handset, the category is your only option, and the default exit for sound in that category is the handset (in the absence of an external device). Note: Not an app can only use a category, the program should be based on the actual need to switch the different category, for example, when recording, it needs to be set to Avaudiosessioncategoryrecord, when the recording ends, You should change the category to Avaudiosessioncategoryambient,avaudiosessioncategorysoloambient or AV according to your program needsOne of the audiosessioncategoryplayback. <pre name= "code" class= "OBJC" > Set category
Nserror *setcategoryerror = nil; BOOL success = [[Avaudiosession sharedinstance] setcategory:avaudiosessioncategoryambient Error: & Setcategoryerror]; if (!success) {/* Handle the error in Setcategoryerror */}
The choice of avaudiosessioncategory