Is it possible to record audio in iOS with Codename One?

时光毁灭记忆、已成空白 提交于 2019-12-06 11:34:27

Have you looked at the Capture class? That seems to be more straightforward.

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

Ok I got it working by overloading some methods of the MediaManager, namely getAvailableRecordingMimeTypes() and also createMediaRecorder() to prevent it from using its getAvailableRecordingMimeTypes method.

Here is the code for 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() is left as is (copied without changes).

Now it is possible to record audio in iOS and play it back in both iOS and Android!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!