Jump to content
Sign in to follow this  
philipp.hofmann

Audio Session Initialization for iOS

Recommended Posts

Hi,

 

I have to make the following settings for a test with a video chat software:
"What you can try, if you haven't already, would be to set the AVAudioSession to Mode AVAudioSession.Mode.videoChat and add the AVAudioSession.CategoryOption.mixWithOthers."

The reason is that currently as soon as I enter the video chat room, the music played in the app stops playing.
Now I've tried this with the following code:

 

procedure TicTrainerF.initIOSAudioSession();
var AudioSession: AVAudioSession;
    LErrorPtr: Pointer;
    LError: NSError;
    hasError: boolean;
begin
  mlog.info('initIOSAudioSession');
  hasError:=false;
  LErrorPtr := nil;
  AudioSession := TAVAudioSession.Wrap(TAVAudioSession.OCClass.sharedInstance);
  if (not hasError) then
  begin
    AudioSession.setMode(CocoaNSStringConst(libAVFoundation, 'AVAudioSessionModeVideoChat'),@LErrorPtr);
    if (LErrorPtr <> nil) then
    begin
      LError := TNSError.Wrap(LErrorPtr);
      mlog.info('initIOSAudioSession-Error (setMode): '+NSStrToStr(LError.localizedDescription));
      hasError:=true;
    end;
  end;
  if (not hasError) then
  begin
    AudioSession.setCategory(CocoaNSStringConst(libAVFoundation, 'AVAudioSessionCategoryOptionMixWithOthers'),@LErrorPtr);
    if (LErrorPtr <> nil) then
    begin
      LError := TNSError.Wrap(LErrorPtr);
      mlog.info('initIOSAudioSession-Error (setCategory): '+NSStrToStr(LError.localizedDescription));
      hasError:=true;
    end;
  end;
  if (not hasError) then
    mlog.info('initIOSAudioSession: finished successfully');
end;

 

 

But I get an OSStatus error -50 error back during the calls.
What else is wrong here?

Regards, Philipp

Share this post


Link to post
5 hours ago, philipp.hofmann said:

But I get an OSStatus error -50 error back during the calls.

What category are you setting the audio session to? According to the docs for AVAudioSessionCategoryOptionMixWithOthers, it needs to be one of: AVAudioSessionCategoryPlayAndRecord, AVAudioSessionCategoryPlayback, or AVAudioSessionCategoryMultiRoute:

 

https://developer.apple.com/documentation/avfaudio/avaudiosessioncategoryoptions/avaudiosessioncategoryoptionmixwithothers

 

You might also want to read the docs on AVAudioSessionModeVideoChat:

 

https://developer.apple.com/documentation/avfaudio/avaudiosessionmodevideochat

 

Also, what description is it giving for the error, and which calls, exactly? "the calls" is too vague.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×