Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6923677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:33:57+00:00 2026-05-27T10:33:57+00:00

I was googling this problem for many days but I didn’t find a solution

  • 0

I was googling this problem for many days but I didn’t find a solution for my simple problem.

I’m trying to play a video while recording sound. Recording sound works fine without the video. And the video works fine without the recording.

As soon as I put both together, the recording throws values which do not react on sound and the video is not playing anymore.
By the way this happens only on my device (iPhone 4 / iOS5). In the simulator everything works fine.

This is a reduced version of my code which is in a ViewController.

// Audio Recorder

NSURL *nullUrl = [NSURL fileURLWithPath:@"/dev/null"];

NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithFloat:44100.0],                 AVSampleRateKey,
                          [NSNumber numberWithInt:kAudioFormatAppleLossless], AVFormatIDKey,
                          [NSNumber numberWithInt:1],                         AVNumberOfChannelsKey,
                          [NSNumber numberWithInt:AVAudioQualityMax],         AVEncoderAudioQualityKey,
                          nil];

NSError *recorderError;
_recorder = [[AVAudioRecorder alloc] initWithURL:nullUrl settings:settings error:&recorderError];

if (_recorder)
{
    [_recorder prepareToRecord];
    _recorder.meteringEnabled = YES;
    [_recorder record];

    _levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(levelTimerCallback:) userInfo:nil repeats:YES];
}


// Video Player

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Video"
                                      withExtension:@"mp4"
                                       subdirectory:nil];

_avPlayer = [[AVPlayer playerWithURL:url] retain];
_avPlayerLayer = [[AVPlayerLayer playerLayerWithPlayer:_avPlayer] retain];

_avPlayerLayer.frame = self.view.layer.bounds;
[self.view.layer addSublayer:_avPlayerLayer];

[_avPlayer play];

The recorder simply outputs a value which is read in the levelTimerCallback method.
The video simply plays a short video.

I figured out that I have to set a category for the AVAudioSession.
If I implement this code after app start, the video is playing but the recorder still outputs the same values without reacting to sound.

NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
[audioSession setActive:YES error:&error];

I could imagine that I might have to do something with AudioSessionSetProperty

UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);    

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

But that doesn’t change anything.
Do you have an idea what I am missing or how to set up the AudioSession properly?

Thank you for every hint on that!

Cheers,
Raphael 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:33:58+00:00Added an answer on May 27, 2026 at 10:33 am

    I had the same problem (except I’m using the AVPlayer to play audio and not video though). I suggest you start listening for audio routing changes and you will see the route change multiple times when the AVPlayer and AVAudioRecorder are started at the same time.

    AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange,
                                    audioRouteChangeListenerCallback,
                                    self);
    

    In the callback print out the category and route (kAudioSessionProperty_AudioRoute). The only way I could get the audio playback and record to work simultaneously was if:

    1. The audio session was AVAudioSessionCategoryPlayAndRecord and kAudioSessionProperty_OverrideCategoryMixWithOthers property was true.

    2. I initiated the playback before the recording. After AVAudioRecorder prepareToRecord is called, don’t start recording until you get the audio route change. Even though it does not fail if you start recording earlier, the audio route change seems to make the recording fail.

    I tried other combinations, but this is the only one that works every time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a very simple problem, but I couldn't find an answer googleing
I tried googling for this issue and found many people with the same problem
I have been googling/SO:ing this issue for a while and many seem to be
After many sites searched and googling, I can't find anything for my problem. I
I guess the topic says it. I have tried googling this, but havent gotten
I've done quite a bit of googling on this error but have had no
While I'm googling/reading for this answer I thought I would also ask here. I
I did some googling to try to answer this question but even after that
Ok, this question has been asked many times. Just googling with the error message:
I'm now working on a problem I can't find a name for, so googling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.