Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 这是一个奇怪的问题。录音机没有停止_Ios_Iphone_Objective C_Ios7_Iphone 5 - Fatal编程技术网

Ios 这是一个奇怪的问题。录音机没有停止

Ios 这是一个奇怪的问题。录音机没有停止,ios,iphone,objective-c,ios7,iphone-5,Ios,Iphone,Objective C,Ios7,Iphone 5,我正在开发一个应用程序,在这个应用程序中我使用了录音机。我的录音机在应用程序关闭时停止。当我的应用程序处于后台时,红色状态栏显示 使用此代码 NSArray *pathComponents = [NSArray arrayWithObjects: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject

我正在开发一个应用程序,在这个应用程序中我使用了录音机。我的录音机在应用程序关闭时停止。当我的应用程序处于后台时,红色状态栏显示

使用此代码

NSArray *pathComponents = [NSArray arrayWithObjects:
                                   [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
                                   @"MyAudioMemo.m4a",
                                   nil];
        NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];

        // Setup audio session
        AVAudioSession *session = [AVAudioSession sharedInstance];
        //[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

        [session setCategory:AVAudioSessionCategoryRecord error:nil];

        // Define the recorder setting
        NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];

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

        // Initiate and prepare the recorder
        delegate.recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:nil];

        delegate.recorder.delegate=self;

        delegate.recorder.meteringEnabled = YES;
        [delegate.recorder prepareToRecord];


        //[recorder record];  // Do not start recording here

        [delegate.recorder updateMeters];
        level = [delegate.recorder peakPowerForChannel:0];

        //AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        //[audioSession setActive:NO error:nil];


        timer = [NSTimer scheduledTimerWithTimeInterval:0.2  target:self
                                               selector:@selector(updateAudioMeter)
                                               userInfo:nil
                                                repeats:YES];



-(void)updateAudioMeter
{
    AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];

    [delegate.recorder updateMeters];


    level = [delegate.recorder averagePowerForChannel:0];

    NSLog(@"%f",level);

    if(level<=-120)
    {
        [delegate.recorder record];
    }
    else
    {
        [delegate.recorder stop];
    }
}


- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [recorder stop];
}
NSArray*pathComponents=[NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是)lastObject],
@“MyAudioMemo.m4a”,
零];
NSURL*outputFileURL=[NSURL fileURLWithPathComponents:pathComponents];
//设置音频会话
AVAudioSession*会话=[AVAudioSession sharedInstance];
//[会话集类别:AvaudioSessionCategory播放和记录错误:无];
[session setCategory:AVAudioSessionCategoryRecord错误:nil];
//定义记录器设置
NSMutableDictionary*记录设置=[[NSMutableDictionary alloc]init];
[recordSetting setValue:[NSNumber NumberWiint:kAudioFormatMPEG4AAC]forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0]forKey:AVSampleRateKey];
[记录设置设置值:[NSNumber numberWithInt:2]forKey:AVNumberOfChannelsKey];
//启动并准备记录器
delegate.recorder=[[AVAudioRecorder alloc]initWithURL:outputFileURL设置:记录设置错误:nil];
delegate.recorder.delegate=self;
delegate.recorder.meteringEnabled=是;
[代表.记录员准备记录];
//[录音机记录];//不要在这里开始录音
[delegate.recorder updateMeters];
级别=[delegate.recorder峰值功率或通道:0];
//AVAudioSession*audioSession=[AVAudioSession sharedInstance];
//[audioSession setActive:无错误:无];
计时器=[NSTimer scheduledTimerWithTimeInterval:0.2目标:自身
选择器:@selector(updateAudioMeter)
用户信息:无
重复:是];
-(无效)更新度数计
{
AppDelegate*委托=(AppDelegate*)[[UIApplication sharedApplication]委托];
[delegate.recorder updateMeters];
级别=[delegate.recorder averagePowerForChannel:0];
NSLog(@“%f”,级别);

如果(level您是关闭它还是真的终止它?您是如何处理
ApplicationIdentinterBackground:
通知的?您是在那里停止记录器吗?@neilco这样做但不起作用。在ApplicationIdentinterBackground中停止记录器:但不起作用。请帮助…向我们展示您的
ApplicationIdentinterBackground:
实现@JitendraDeore“不起作用”是毫无帮助的含糊不清。请具体说明您的回答。到底是什么不起作用?向我们展示您的代码。