无法在iOS 5中播放Android中录制的音频文件

前端之家收集整理的这篇文章主要介绍了无法在iOS 5中播放Android中录制的音频文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发支持iOS的 Android应用程序.我想录制音频&在Android和iOS设备中播放它.我正在使用以下设置在Android中录制音频
MediaRecorder audioRecorder = new MediaRecorder();
audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
audioRecorder.setAudioSamplingRate(44100);
audioRecorder.setAudioChannels(1);
audioRecorder.setAudioEncodingBitRate(12800);
audioRecorder.setOutputFile(<recordedSoundFilePath>);
audioRecorder.prepare();
audioRecorder.start();

在iOS端,设置如下

//audioRecorder is object of  AVAudioRecorder 

NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10];
    NSNumber *formatObject;
    formatObject = [NSNumber numberWithInt: kAudioFormatMPEG4AAC ];

    [recordSettings setObject:formatObject forKey: AVFormatIDKey];
    [recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
    [recordSettings setObject:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
    [recordSettings setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
    [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    [recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey: AVEncoderAudioQualityKey];

    NSURL *soundFileURL = [NSURL fileURLWithPath:[self soundFilePath]];

    NSError *error = nil;
    audioRecorder = [[ AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSettings error:&error];

    if ([audioRecorder prepareToRecord] == YES){
        [audioRecorder record];
    }else {
        int errorCode = CFSwapInt32HostToBig ([error code]);
        NSLog(@"Error: %@ [%4.4s])",[error localizedDescription],(char*)&errorCode);

    }

我可以录制音频&它在Android设备中正常播放.
现在问题是我可以在Android设备上播放iOS录制的音频,但iOS设备无法播放Android设备上录制的音频.它返回OSStatus错误1937337955.我搜索了这个错误,但我找不到任何东西.

谁能告诉我代码中出了什么问题?

任何形式的帮助都非常感谢.提前致谢.

解决方法

试试这个:
audioRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
原文链接:https://www.f2er.com/iOS/333526.html

猜你在找的iOS相关文章