是否有可能在iOS中使用Codename One录制音频?

是否有可能在iOS中使用Codename One录制音频?

问题描述:

我的应用程序具有录制音频的按钮(另一个可在录制结束时播放)。我将录制的音频文件发送到服务器上。在Android上,文件记录为.amr(mime type audio/amr)并可以播放。是否有可能在iOS中使用Codename One录制音频?

在iOS上,该文件既不能在设备(iPhone 4或4S)上播放,也不能在计算机上播放。 ffmpeg -i报告

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x2fac120] moov atom not found 
9gMjOnnmsj9JJZR3.m4a: Invalid data found when processing input 

请注意,VLC也不能玩。

我给m4a扩展,因为录音机使用它(以及aac编解码器)。

这里是我使用的代码(主要是基于https://github.com/codenameone/CodenameOne/blob/master/Ports/iOSPort/src/com/codename1/impl/ios/IOSImplementation.java#L2768-L2794):如果我显示在iOS可用MIME类型,它产生“音频/ AMR”,我根据所有帖子怀疑

audioMemoPath = ParametresGeneraux.getWRITABLE_DIR() + "AudioMemo-" 
      + System.currentTimeMillis() + 
      (Display.getInstance().getPlatformName().equals("and") 
      ? ".amr" 
      : ".m4a"); 
audioMemoMimeType = MediaManager.getAvailableRecordingMimeTypes()[0]; 

audioMemoRecorder = MediaManager.createMediaRecorder(audioMemoPath, audioMemoMimeType); 

// If the permission audio has not been granted 
// the audiomemorecoreder will be null 
    if (audioMemoRecorder != null) { 
      audioMemoRecorder.play(); 
      boolean b = Dialog.show("Recording", "", "Save", "Cancel"); 
      audioMemoRecorder.pause(); 
      audioMemoRecorder.cleanup(); 

      ... 
     } 

而且我可以读懂,告诉你在iOS上不支持amr。查看源看来AMR是由默认的MIME类型,因为它总是返回:

/** 
* Gets the available recording MimeTypes 
*/ 
public String [] getAvailableRecordingMimeTypes(){ 
    return new String[]{"audio/amr"}; 
} 

所以我的问题:是否有可能记录在iOS上的音频,如果是,如何才能做到呢?

任何帮助表示赞赏,

好我得到了它通过重载MediaManager,即getAvailableRecordingMimeTypes()createMediaRecorder()的一些方法,以防止它使用其getAvailableRecordingMimeTypes方法工作。

下面是getAvailableRecordingMimeTypes()的代码:

/** 
* Normally the method returns amr even for ios. So we overload the original 
* method to return aac on ios. 
* @return 
*/ 
public static String[] getAvailableRecordingMimeTypes() { 
    if (Display.getInstance().getPlatformName().equals("ios")) { 
     return new String[]{"audio/aac"}; 
    } else { 
     return new String[]{"audio/amr"}; 
    } 

} 

createMediaRecorder()保留为被(复制不变化)。

现在有可能在iOS中录制音频并在iOS和Android上播放!

你看过Capture类吗?这似乎更直接。

https://www.codenameone.com/javadoc/index.html

+0

谢谢詹姆斯。然而,我需要限制录音时间,这就是为什么我诉诸'MediaRecorder'。但是我可以从Capture开始查看输出结果。 – HelloWorld

+0

我试过你的建议,但录制的文件无法在移动设备上播放(详情请参阅http://*.com/questions/43193249/is-it-possible-to-record-audio-in-ios-with- codename-one) – HelloWorld

+0

我的意思是那里的细节! http://*.com/questions/43226775/why-is-codename-one-on-ios-recording-audio-as-caf – HelloWorld