程序突然有很多错误

时间:2011-10-12 07:02:17

标签: objective-c xcode ios5 avaudiorecorder

过去几个月我一直在制定计划。我终于达到了一切都很好的地步。该程序从一开始就是为iOS 5构建的。我刚刚查看了我认为已经粘合的东西,并且在我几天前检查时工作正常。但现在一切都表现得很傻。我的录音机停止工作。不知道在哪个方面。我的寻求者的价值观正在发生变化。播放录音无效。记录器过去需要一秒钟才能加载它会冻结屏幕的地方然后开始,现在它是瞬间的,我觉得很奇怪。对不起,如果我是模糊的,但我完全难过。记录按钮在记录命令之后设置计时器。在计时器中有一个if语句,它有许多子句,一个是myRecorder.isRecording == NO,但if语句就好像满足条件并执行里面的代码,尽管记录器被告知要在之前记录计时器甚至开始了。我是BAFFLED。请帮忙。感谢

记录按钮代码: - (IBAction)记录:(id)sender {         // [myPlayer play];

if ([sender tag] == 2){
    [self stop];
    [sender setTag:1];
    [sender setTitle:@"Record"];
    [sender setEnabled:NO];
    NSLog(@"Tag is 2");
}else{
    if ([myPlayer isPlaying]){
        [myPlayer pause];
        [myPlayer setCurrentTime:0];
    }
    anotherControl = 0; 
    theToolbar.userInteractionEnabled = NO;
    [theToolbar setTintColor:myColor];
    [theToolbar setAlpha:.5];
    [controlSong setTintColor:[UIColor blackColor]];
    beatPackTable.userInteractionEnabled = NO;
    beatPackTable.hidden = YES;
    onScreenTut.text = @"(Hold phone to your face and begin. When finished recording, hit the stop button)";
    recordCover.titleLabel.text = @"Recording";
    recordCover.titleLabel.textAlignment = UITextAlignmentCenter;
    recordCover.hidden = NO;
    NSString *docsDir;
    myDate = [[NSDate alloc] init];
    myDate = [NSDate date];
    seekerTwo.userInteractionEnabled = NO;
    homeButton.enabled = NO;
    tracksButton.enabled = NO;
    tutButton.enabled = NO;
    previewBeatTwo.enabled = NO;
    previewPauseTwo.enabled = NO;

    /*    
     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
     [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
     [dateFormatter setDateStyle:NSDateFormatterShortStyle];
     NSString *myDate2 = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:myDate]];
     */    
    //    dirPaths = NSSearchPathForDirectoriesInDomains(
    //                                                   NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = NSTemporaryDirectory();


    NSString *soundFilePath = [docsDir
                               stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%i.caf",myDate,control]];

    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

    NSDictionary *recordSettings = [NSDictionary 
                                    dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithInt:AVAudioQualityLow],
                                    AVEncoderAudioQualityKey,
                                    [NSNumber numberWithInt:16], 
                                    AVEncoderBitRateKey,
                                    [NSNumber numberWithInt: 2], 
                                    AVNumberOfChannelsKey,
                                    [NSNumber numberWithFloat:44100.0], 
                                    AVSampleRateKey,
                                    nil];

    NSError *error = nil;



    myNewRecorder = [[AVAudioRecorder alloc]
                  initWithURL:soundFileURL
                  settings:recordSettings
                  error:&error];

    if (error)
    {
        NSLog(@"error: %@", [error localizedDescription]);

    } else {
        [myNewRecorder prepareToRecord];}




    seeker.userInteractionEnabled = NO;
    voiceVolumeControl.enabled =YES;
    recordButton.enabled = NO;

    stopButton.enabled = YES;


    myPlayer.currentTime = 0;
    [myNewRecorder record];
    [myPlayer play];
    [NSTimer scheduledTimerWithTimeInterval:1.0f
                                     target:self
                                   selector:@selector(updateCounter:)
                                   userInfo:nil
                                    repeats:YES];

if ([sender tag] == 1){
    [sender setTitle:@"End"];
    [sender setTag:2];

}}
NSLog(@"%@",myDate);
}

计时器代码:

- (void)updateCounter:(NSTimer *)theTimer {

    if ([myNewRecorder isRecording]) {
        [seeker setValue:myPlayer.currentTime/myPlayer.duration animated:YES];}

    if ([myPlayer2 isPlaying])
    {
        [seeker setValue:myPlayer2.currentTime/myPlayer2.duration animated:YES];
    }

    if ([myPlayer isPlaying] && myPlayer2.isPlaying == NO && myNewRecorder.isRecording == NO && isNotepadOpen == NO && anotherControl == 0) {
        [myPlayer stop];
        myPlayer.currentTime = 0;
        [seeker setValue:0];
        playButton.enabled = YES;
        stopButton.enabled = NO;
        NSLog(@"Its the timer for some reason");
    }

    if ([myNewRecorder isRecording] || [myPlayer isPlaying] || [myPlayer2 isPlaying]){
        [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
    }else{
        [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
    }
    if ([myPlayer isPlaying]){
        [seekerTwo setValue:myPlayer.currentTime/myPlayer.duration animated:YES];
    }
}

1 个答案:

答案 0 :(得分:1)

在程序员SE上查看我的答案(和其他人):“It was working yesterday, I swear!” What can you do?

基本上,找到自突发错误以来发生的变化,可能是iOS 5,Xcode或软件使用的外部库的新交付。