4

我正在开发一个基于 sip 呼叫的应用程序,如果有人开始呼叫并退出应用程序,我想在后台发送呼叫。在这种情况下,我想在屏幕上显示呼叫持续时间。为此,我正在使用 in_call 状态栏。但是我使用的代码是将 in_call 状态栏的背景颜色设置为红色,我不知道如何将其颜色更改为绿色也想在上面显示计时器。当我第一次使用这个时,我不知道如何解决这个。这是我的代码。如果有人可以,请提供帮助。我在didFinishLaunchingWithOptions方法上调用此方法

    +(void) startRecording {
    AVAudioSession * audioSession = [AVAudioSession sharedInstance];
    NSError * err = nil;
    [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: & err];
    if (err) {
        NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [
            [err userInfo] description
        ]);
        return;
    }
    [audioSession setActive: YES error: & err];
    err = nil;
    if (err) {
        NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [
            [err userInfo] description
        ]);
        return;
    }


    NSMutableDictionary * recordSetting = [
        [NSMutableDictionary alloc] init
    ];

    [recordSetting setValue: [NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey];
    [recordSetting setValue: [NSNumber numberWithFloat: 44100.0] forKey: AVSampleRateKey];
    [recordSetting setValue: [NSNumber numberWithInt: 2] forKey: AVNumberOfChannelsKey];

    [recordSetting setValue: [NSNumber numberWithInt: 16] forKey: AVLinearPCMBitDepthKey];
    [recordSetting setValue: [NSNumber numberWithBool: NO] forKey: AVLinearPCMIsBigEndianKey];
    [recordSetting setValue: [NSNumber numberWithBool: NO] forKey: AVLinearPCMIsFloatKey];


    NSURL * url = [NSURL fileURLWithPath: @"/dev/null"];
    err = nil;
    AVAudioRecorder * recorder = [
        [AVAudioRecorder alloc] initWithURL: url settings: recordSetting error: & err
    ];
    if (!recorder) {
        NSLog(@"recorder: %@ %d %@", [err domain], [err code], [
            [err userInfo] description
        ]);
        UIAlertView * alert = [
            [UIAlertView alloc] initWithTitle: @"Warning"
            message: [err localizedDescription]
            delegate: nil
            cancelButtonTitle: @"OK"
            otherButtonTitles: nil
        ];
        [alert show];
        return;
    }

    //prepare to record
    [recorder setDelegate: self];
    [recorder prepareToRecord];
    recorder.meteringEnabled = YES;

    BOOL audioHWAvailable = audioSession.inputIsAvailable;
    if (!audioHWAvailable) {
        UIAlertView * cantRecordAlert = [
            [UIAlertView alloc] initWithTitle: @"Warning"
            message: @"Audio input hardware not available"
            delegate: nil
            cancelButtonTitle: @"OK"
            otherButtonTitles: nil
        ];
        [cantRecordAlert show];
        return;
    }

    // start recording
    [recorder record]; //recordForDuration:(NSTimeInterval) 40];
}
4

0 回答 0