4

我有一个应用程序,我需要在其中录制音频,然后将其上传到服务器并将文件的链接邮寄给用户。

现在,当我尝试在 mac 或 windows 中打开邮件时,它工作正常,我可以听到音频。但是当我尝试在 iPhone 或 iPad 中打开链接时,它不会在其中播放。

虽然我为该项目制作了一个演示应用程序,当我尝试同样的事情时,它确实有效。

请帮帮我。

先感谢您。

    NSArray *dirPaths;
    NSString *docsDir;

    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = [dirPaths objectAtIndex:0];


    if ([txt_RecordingName.text isEqualToString:@"Untitled"])
    {
        strFileName = [NSString stringWithFormat:@"Recording %d.m4a",[appDelegate.db getMaxId]];
        soundFilePath = [docsDir stringByAppendingPathComponent:strFileName];
    }
    else
    {
        strFileName = [NSString stringWithFormat:@"%@.m4a",txt_RecordingName.text];
        soundFilePath = [docsDir stringByAppendingPathComponent:strFileName];
    }
    NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
                                    [NSNumber numberWithFloat:16000.0], AVSampleRateKey,
                                    [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
                                    nil];

    newURL = [NSURL fileURLWithPath:soundFilePath];
    audioRecorder = [[AVAudioRecorder alloc]
                     initWithURL:newURL
                     settings:recordSettings
                     error:nil];
    audioRecorder.delegate = self;
    [audioRecorder prepareToRecord];

    if (!audioRecorder.recording)
    {
        AVAudioSession *session = [AVAudioSession sharedInstance];
        [session setCategory:AVAudioSessionCategoryRecord error:nil];
        [session setActive:YES error:nil];
        [audioRecorder record];
        counter = 0;
        [btnPauseRecord setEnabled:TRUE];
    }
    recordingTime = -1;
    [self showRecordingTime];
    [lbl_Recording setHidden:NO];
    [lbl_PressToStop setText:@"Press to pause"];
    [lbl_PressToStop setHidden:NO];
    [lbl_ListenToRecording setHidden:YES];
    [lbl_RecordingAgain setHidden:YES];
    [btn_ListenToRecording setHidden:YES];
    [btn_RecordAgain setHidden:YES];
    txt_RecordingName.text = strFileName;
}
else
{
    [audioRecorder stop];
    audioRecorder = nil;
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setActive:NO error:nil];

    isRecording = FALSE;

    [btnPauseRecord setEnabled:FALSE];
    [txt_RecordingName setEnabled:TRUE];
    isPaused = TRUE;
    [lbl_Recording setHidden:YES];
    [lbl_Save setHidden:NO];
    [btn_Save setHidden:NO];
    [lbl_ListenToRecording setHidden:NO];
    lbl_ListenToRecording.text = @"Listen to Recording";
    [lbl_RecordingAgain setHidden:NO];
    [btn_ListenToRecording setHidden:NO];
    [btn_RecordAgain setHidden:NO];
    lbl_PressToStop.text = @"Press to resume";
    [lblPauseRecord setHidden:YES];
    [btnPauseRecord setHidden:YES];
}
4

0 回答 0