Cannot play .m4a file in safari recorded in iOS app.

I have an application in which I need to record audio and upload it to the server and send the file link to the user.

Now when I try to open mail on Mac or Windows, it works fine and I hear a sound. But when I try to open the link on the iPhone or iPad, it will not play it.

While I had a demo application for the project, and when I try to do the same thing, it worked.

Please help me.

Thanks in advance.

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
source share

Source: https://habr.com/ru/post/1492091/


All Articles