Comments (3)
Hello, everyone :)
If you are using this example in your app and experiencing issue with speakerphone instead of headset, you need to do some changes in the custom audio driver - OTDefaultAudioDevice
.
- Remove from audio session setup -
setupAudioSession
andsetupAudioSession:(AVAudioSession *)audioSession
setting of default speaker option:
audioOptions |= AVAudioSessionCategoryOptionDefaultToSpeaker;
- In same session setup methods change audio session mode from
Video
[mySession setMode:AVAudioSessionModeVideoChat error:nil];
to Voice
[mySession setMode:AVAudioSessionModeVoiceChat error:nil];
- If you need to turn on headset by default (after previous steps it should be chosen by default, but if not...) you can force set it manually by calling
[self configureAudioSessionWithDesiredAudioRoute:AUDIO_DEVICE_HEADSET];
You can do this also in the setupAudioSession
or before creation and connection to the OpenTok session.
Here is how setupAudioSession
looks like after changes:
- (void) setupAudioSession
{
AVAudioSession *mySession = [AVAudioSession sharedInstance];
_previousAVAudioSessionCategory = mySession.category;
avAudioSessionMode = mySession.mode;
avAudioSessionPreffSampleRate = mySession.preferredSampleRate;
avAudioSessionChannels = mySession.inputNumberOfChannels;
[mySession setPreferredSampleRate: kSampleRate error: nil];
[mySession setPreferredInputNumberOfChannels:1 error:nil];
[mySession setPreferredIOBufferDuration:kPreferredIOBufferDuration
error:nil];
NSError *error = nil;
NSUInteger audioOptions = 0;
#if !(TARGET_OS_TV)
audioOptions |= AVAudioSessionCategoryOptionAllowBluetooth ;
[mySession setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:audioOptions
error:&error];
#else
[mySession setCategory:AVAudioSessionCategoryPlayback
withOptions:audioOptions
error:&error];
#endif
[mySession setMode:AVAudioSessionModeVoiceChat error:nil];
if (error)
OT_AUDIO_DEBUG(@"Audiosession setCategory %@",error);
error = nil;
[self setupListenerBlocks];
[self configureAudioSessionWithDesiredAudioRoute:AUDIO_DEVICE_HEADSET];
[mySession setActive:YES error:&error];
if (error)
OT_AUDIO_DEBUG(@"Audiosession setActive %@",error);
}
- Don't forget to pre-heat audio session before starting CallKit's AudioSession as TokBox provided in example - in
CXStartCallAction
andCXAnswerCallAction
Minor explanation why it's all happening with us :)
- When Audio Session configured with
AVAudioSessionCategoryOptionDefaultToSpeaker
it's obviously uses speaker by default :) - When you choose
AVAudioSessionModeVideoChat
mode, session obviously (for Apple :D) uses speaker by default and you can't switch because... it's Apple's logic, I suppose. - And if session is configured with
AVAudioSessionModeVoiceChat
mode, iOS and CallKit behaves as voice call with ability yo switch between speakers (and also turning screen off when user brings phone to ear).
BTW, from Apples documentation:
/* Only valid with kAudioSessionCategory_PlayAndRecord. Reduces the number of allowable audio
routes to be only those that are appropriate for video chat applications. May engage appropriate
system-supplied signal processing. **Has the side effect of setting
AVAudioSessionCategoryOptionAllowBluetooth and AVAudioSessionCategoryOptionDefaultToSpeaker.** */
AVF_EXPORT AVAudioSessionMode const AVAudioSessionModeVideoChat API_AVAILABLE(ios(7.0), watchos(2.0), tvos(9.0)) API_UNAVAILABLE(macos);
And also, from documentation, Apple suggests to use AVAudioSessionModeVoiceChat
for both audio and video calls.
from callkit.
@mrazam110 thanks for this concise report. We'll work on that change.
from callkit.
Hi, any updates on this?
from callkit.
Related Issues (15)
- No ringtone in StandBy Mode on iPad HOT 3
- basic_streambuf<char, std error HOT 5
- Show custom UI after answer call from locked screen HOT 1
- New issue Your development team does not support the Push Notifications capability.
- Hold state is not supported
- Open Incoming Calling screen into my app
- Ringtone in app
- How to connect call on receive button click
- Not starting call from recent log
- Video stream for multiple subscribers VoIP push issue
- problem with call from locked screen
- Lost audio when go to app in call screen when change from callkit screen
- Dismissing call banner when source cancels the call.
- Can this be used with video? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from callkit.