Low recording volume in combination with AVAudioSessionCategoryPlayAndRecord

前端 未结 7 1775
我在风中等你
我在风中等你 2020-12-04 18:30

When I set:

[[AVAudioSession sharedInstance] setCategory:
    AVAudioSessionCategoryPlayAndRecord error:NULL];

…recording and playing works

7条回答
  •  旧巷少年郎
    2020-12-04 18:53

    I found out (cf. Listing 7-9 in the iOS documentation) that the suggested solution above on overriding the audio route stops working after plugging, and removing earphones.

    So, if you want the change in audio route to be permanent in the current audio session (Listing 7-10 in the iOS documentation) the same source you can set the default audio route by instead using

    NSError *setCategoryErr = nil;
    NSError *activationErr  = nil;
    //Set the general audio session category
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: &setCategoryErr];
    
    //Make the default sound route for the session be to use the speaker
    UInt32 doChangeDefaultRoute = 1;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);
    
    //Activate the customized audio session
    [[AVAudioSession sharedInstance] setActive: YES error: &activationErr];
    

    and of course make sure to link the AudioToolbox framework and import it using

    #import 
    

提交回复
热议问题