无法在iOS应用程序中记录的safari中播放.m4a文件

时间:2013-07-18 13:22:21

标签: avaudiorecorder avaudiosession m4a

我正在申请我需要录制音频,然后将其上传到服务器并将文件的链接邮寄给用户。

现在,当我尝试在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];
}

0 个答案:

没有答案