Created
July 3, 2019 03:37
-
-
Save yccheok/cb3953eb101a905059d603fb1ffc3d64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private boolean isHeAacEncoderSupported() { | |
| if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { | |
| int numCodecs = MediaCodecList.getCodecCount(); | |
| for (int i = 0; i < numCodecs; i++) { | |
| MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i); | |
| if (!codecInfo.isEncoder()) { | |
| continue; | |
| } | |
| for (String supportedType : codecInfo.getSupportedTypes()) { | |
| if (supportedType.equalsIgnoreCase(MIMETYPE_AUDIO_AAC)) { | |
| MediaCodecInfo.CodecCapabilities cap = codecInfo.getCapabilitiesForType(MIMETYPE_AUDIO_AAC); | |
| MediaCodecInfo.CodecProfileLevel[] profileLevels = cap.profileLevels; | |
| for (MediaCodecInfo.CodecProfileLevel profileLevel : profileLevels) { | |
| int profile = profileLevel.profile; | |
| if (profile == MediaCodecInfo.CodecProfileLevel.AACObjectHE || profile == MediaCodecInfo.CodecProfileLevel.AACObjectHE_PS) { | |
| return true; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| return false; | |
| } | |
| private void startMediaRecorder() { | |
| mediaRecorder = new MediaRecorder(); | |
| mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); | |
| mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); | |
| mediaRecorder.setAudioChannels(1); | |
| mediaRecorder.setAudioSamplingRate(8000); | |
| mediaRecorder.setAudioEncodingBitRate(32000); | |
| mediaRecorder.setMaxDuration(RECORDING_MEDIA_RECORDER_MAX_DURATION); | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
| if (isHeAacEncoderSupported()) { | |
| mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC); | |
| trackEvent("startMediaRecorder", "setAudioEncoder", "HE_AAC"); | |
| } else { | |
| mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); | |
| trackEvent("startMediaRecorder", "setAudioEncoder", "AAC"); | |
| } | |
| } else { | |
| mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); | |
| trackEvent("startMediaRecorder", "setAudioEncoder", "AAC"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment