Sonu
Sonu

Reputation: 957

How can stream Audio when iPhone is locked?

I'm working on AppRTC for Audio call, It's working fine when app is open. Audio call is not working when device is locked, If wI un-lock device while call and open app, It's start working normally but while it's locked it's not working. (Audio is not passing or playing).

I already added "App plays audio or streams audio/video using AirPlay" in "Required background modes" of plist.

Audio session is also configured. Please check code below.

- (void)configureAVAudioSession:(BOOL)isSpeakerOn
{
    // Get your app's audioSession singleton object
    AVAudioSession *session = [AVAudioSession sharedInstance];

    // Error handling
    BOOL success;
    NSError *error;

    // set the audioSession category.
    // Needs to be Record or PlayAndRecord to use audioRouteOverride:

    success = [session setCategory:AVAudioSessionCategoryPlayAndRecord
                             error:&error];

    if (!success) {
        NSLog(@"AVAudioSession error setting category:%@",error);
    }

    // Set the audioSession override
    success = [session overrideOutputAudioPort:isSpeakerOn?AVAudioSessionPortOverrideSpeaker:AVAudioSessionPortOverrideNone
                                         error:&error];
    if (!success) {
        NSLog(@"AVAudioSession error overrideOutputAudioPort:%@",error);
    }

    // Activate the audio session
    success = [session setActive:YES error:&error];
    if (!success) {
        NSLog(@"AVAudioSession error activating: %@",error);
    }
    else {
        NSLog(@"AudioSession active");
    }

}

Please let me know if anything is missing or i'd implemented wrongly.

Regards,

Upvotes: 2

Views: 228

Answers (0)

Related Questions