androidaudiomediaandroid-mediacodecaac

How to encode audio AAC in HE-AAC V1 in new android API 33


android api 33 add new fields in android.media.MediaFormat links: https://developer.android.com/sdk/api_diff/33/changes/android.media.MediaFormat https://developer.android.com/reference/android/media/MediaFormat#MIMETYPE_AUDIO_AAC_HE_V1

before this, we can use like this:

codec_ = codecMediaCodec.createEncoderByType(MediaFormat.MIMETYPE_AUDIO_AAC);
MediaFormat format = MediaFormat.createAudioFormat(MediaFormat.MIMETYPE_AUDIO_AAC,
sampleRate, channelCount);
format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectHE);
codec_.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

in api 33, can I createEncoderByType use new mime type MIMETYPE_AUDIO_AAC_HE_V1? is this valid?

codec_ = codecMediaCodec.createEncoderByType(MediaFormat.MIMETYPE_AUDIO_AAC_HE_V1);

Any help would be appreciated.


Solution

  • It's a valid statement.

    At the same time, you are supposed to be ready to handle:

    1. IllegalArgumentException in case there is no codec on the device that declares the support for this media type (and it makes sense to fallback to another format)
    2. IOException in case the codec can't be created for other reasons (and there is not much you can do besides trying again later)