dev*_*XXX 18 format audio android ios
对不起,如果我问的是一般问题.
我们正在开发一个在移动设备上录制和播放音频的应用程序.此应用程序正在为Android和iOS开发.应用程序将使用设备麦克风录制音频并将其存储在服务器中.
用户(在Android和iOS上)可以打开应用程序并播放存储在服务器上的声音.我们使用的声音格式是AAC.在iOS中它的工作正常.我们可以录制和播放AAC文件.
但在Android(三星S3和三星Galaxy Y)上,我们无法以AAC格式录制声音.但在S3中我们可以播放AAC文件.
我的问题是,我们应选择哪种格式用于在Android中录制和播放(应支持从2.3到Jellybean)和iOS.我们应该使用MP4吗?
我们的一个解决方案是,在后端,我们可以将音频文件转换为AAC,MP4或3GP,并根据版本将支持的文件提供给手机.
小智 28
Android和iOS使用相同的服务器来存储记录.保存所有记录时没有任何扩展名.
当Android从服务器下载记录时,我的应用会添加" .aac "扩展名.
使用iOS时,它会添加" .m4a "扩展名.
同样的记录在两个移动平台上都表现良好.
在iOS上录制:
NSDictionary recorderSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithInt:16000],AVSampleRateKey,
[NSNumber numberWithInt:1],AVNumberOfChannelsKey,
[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
nil];
Run Code Online (Sandbox Code Playgroud)
对于Android:
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
myRecorder.setAudioSamplingRate(16000);
myRecorder.setAudioChannels(1);
mRecorder.setOutputFile(fileName);
Run Code Online (Sandbox Code Playgroud)
Jan*_*mal 12
我们最近完成了一个具有这种功能的应用程序,从iOS和Android两种方式录制,下面是我们用于参考的代码.我们依靠我们的web服务和服务器转换为.mp3格式,可以很容易地在两者中播放平台.
//iPhone side code. records m4a file format (small in size)
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithFloat:16000.0], AVSampleRateKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
nil];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSettings error:&error];
if (error)
NSLog(@"error: %@", [error localizedDescription]);
else
[audioRecorder prepareToRecord];
//Android side code. (records mp4 format and it works straight away by giving mp3 extension.)
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioEncodingBitRate(256);
recorder.setAudioChannels(1);
recorder.setAudioSamplingRate(44100);
recorder.setOutputFile(getFilename());
try {
recorder.prepare();
recorder.start();
myCount=new MyCount(thirtysec, onesecond);
myCount.start();
recordingDone=true;
count=0;
handler.sendEmptyMessage(0);
if(progressDialog.isShowing())
progressDialog.dismiss();
} catch (IllegalStateException e) {
e.printStackTrace();
StringWriter strTrace = new StringWriter();
e.printStackTrace(new PrintWriter(strTrace));
CrashReportActivity.appendLog(
"\nEXCEPTION : \n" + strTrace.toString() + "\n",
Comment.this);
} catch (IOException e) {
e.printStackTrace();
StringWriter strTrace = new StringWriter();
e.printStackTrace(new PrintWriter(strTrace));
CrashReportActivity.appendLog(
"\nEXCEPTION : \n" + strTrace.toString() + "\n",
Comment.this);
}
Run Code Online (Sandbox Code Playgroud)
您可以轻松地在.Net中找到从m4a到mp3的转换代码,通过谷歌搜索(lame或faad这样的实用程序).
希望这可以帮助.
我们最近遇到了这个互操作性问题.我们试图在两个平台上以aac格式录制文件,但使用三星手机录制的文件未在iOS中播放.所以我们必须同时使用3gp和aac格式才能在android和ios中的多个设备上播放文件.
以下是我们在Android中录制文件时使用的代码:
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setOutputFile(fileName);
Run Code Online (Sandbox Code Playgroud)
我们将录制文件的扩展名保持为.3gp.
但是在iOS中,录制无法在3gp中执行,因此我们在iOS中的.aac中录制了文件,可以在两个平台上播放.
| 归档时间: |
|
| 查看次数: |
18781 次 |
| 最近记录: |