首页 > 代码库 > iOS——扬声器与听筒的切换

iOS——扬声器与听筒的切换

  1.扬声器模式:

  NSError *error;

    [[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];

    NSLog(@"error:%@",error);

 

  2.听筒模式:

  NSError *error;

  [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];

  NSLog(@"error:%@",error);

iOS——扬声器与听筒的切换