iphone - iPhone 中录制的音频格式在 android 中也支持和播放

标签 iphone android objective-c ios audio-recording

因为我正在用 iphone 录制音频,如下所示:

//Setup the dictionary object with all the recording settings that this
            //Recording sessoin will use
            NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
            [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
            [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
            [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

            //Now that we have our settings we are going to instanciate an instance of our recorder instance.
            //Generate a temp file for use by the recording.
            NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
            NSString *caldate = [now description];

            recordedTmpFile = [[NSString stringWithFormat:@"%@/%@.caf", DOCUMENTS_FOLDER, caldate] retain];
            NSLog(@"Using File called: %@",recordedTmpFile);
            url = [NSURL fileURLWithPath:recordedTmpFile];
            error = nil;
            //Setup the recorder to use this file and record to it.
            recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&error];

但我的问题是应用程序,我正在开发的应用程序也是为 Android 开发的,但使用 iPhone 和 Android 的通用服务器。当我将录制的音频从 iPhone 发布到服务器并尝试在 Android 中播放该音频时,它显示警告为不支持的文件。

我应该录制哪种格式的音频以在 iPhone 和 Android 中播放音频,有什么帮助吗?

我们将不胜感激任何人的帮助。

最佳答案

它以这种方式为我工作:它的 AAC 格式适用于两者,但是当音频在 android 设备上以 AAC 格式编码时,需要将其放入 .m4a 的容器中,才能在 ios 上播放。它的简单更改扩展名。

例如:

    On android device :   morningtune.aac

    Now Just change the extension of the song


   On ios device :   monrningtune.m4a

首先在 Android 设备上,我使用以下参数录制音频

            recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

现在只需将输出音频的扩展名更改为“m4a”

关于iphone - iPhone 中录制的音频格式在 android 中也支持和播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7090140/

相关文章:

ios - 在全屏隐藏所有状态栏、浏览器地址栏的 iPhone 中打开 Asp.Net MVC 4 Web 应用程序

iphone - UIAlertView 不显示

java - Android 播放外部 MP3 : error -- MediaPlayer start called in state 1

android - 需要定义可绘制对象的 'drawable' 属性或子标记

ios - 如何制作uiimageview圆。?

jquery - ipad/iphone 视频无法切换到全屏模式

iOS - 找不到右侧的配置门户选项卡

java - Java中的Readline()不能正确处理中文字符

ios - 从 Appdelegate 访问 UITabBarController

objective-c - 发出一个 block 并等待它完成