本文整理汇总了Java中android.media.MediaFormat.createAudioFormat方法的典型用法代码示例。如果您正苦于以下问题:Java MediaFormat.createAudioFormat方法的具体用法?Java MediaFormat.createAudioFormat怎么用?Java MediaFormat.createAudioFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaFormat
的用法示例。
在下文中一共展示了MediaFormat.createAudioFormat方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkMediaCodecAudioEncoderSupport
import android.media.MediaFormat; //导入方法依赖的package包/类
@TargetApi(MIN_API_LEVEL_AUDIO)
public static int checkMediaCodecAudioEncoderSupport(){
if(getApiLevel()<MIN_API_LEVEL_AUDIO){
Log.d(TAG, "checkMediaCodecAudioEncoderSupport: Min API is 16");
return CODEC_REQ_API_NOT_SATISFIED;
}
final MediaFormat audioFormat = MediaFormat.createAudioFormat(MIME_TYPE_AUDIO, TEST_SAMPLE_RATE, 1);
audioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
audioFormat.setInteger(MediaFormat.KEY_CHANNEL_MASK, AudioFormat.CHANNEL_IN_MONO);
audioFormat.setInteger(MediaFormat.KEY_BIT_RATE, TEST_AUDIO_BIT_RATE);
audioFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
MediaCodec mediaCodec;
try {
mediaCodec = MediaCodec.createEncoderByType(MIME_TYPE_AUDIO);
mediaCodec.configure(audioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mediaCodec.start();
mediaCodec.stop();
mediaCodec.release();
mediaCodec = null;
} catch (Exception ex) {
Log.e(TAG, "Failed on creation of codec #", ex);
return CODEC_ERROR;
}
return CODEC_SUPPORTED;
}
示例2: AudioEncoderCore
import android.media.MediaFormat; //导入方法依赖的package包/类
public AudioEncoderCore(MMediaMuxer MMediaMuxer) throws IOException {
super(MMediaMuxer);
final MediaFormat audioFormat = MediaFormat.createAudioFormat(MIME_TYPE, SAMPLE_RATE, 1);
audioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
audioFormat.setInteger(MediaFormat.KEY_CHANNEL_MASK, AudioFormat.CHANNEL_IN_MONO);
audioFormat.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
audioFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
// audioFormat.setLong(MediaFormat.KEY_MAX_INPUT_SIZE, inputFile.length());
// audioFormat.setLong(MediaFormat.KEY_DURATION, (long)durationInMs );
if (VERBOSE) Log.i(TAG, "format: " + audioFormat);
mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
mEncoder.configure(audioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncoder.start();
if (mAudioThread == null) {
mAudioThread = new AudioThread();
mAudioThread.start();
capturing=true;
stopped=false;
}
}
示例3: mediaFormatFromStaticPayloadType
import android.media.MediaFormat; //导入方法依赖的package包/类
private static MediaFormat mediaFormatFromStaticPayloadType(String m, int p) {
MediaFormat format = null;
PayloadFormat payloadFormat = PayloadFormat.staticPayloadType(p);
if (payloadFormat != null) {
switch (m.toLowerCase()) {
case "audio":
format = MediaFormat.createAudioFormat(
payloadFormat.mimeType,
payloadFormat.clockRate,
payloadFormat.channelCount);
break;
case "video":
// TODO: Video not supported. Not sure how to get video dimensions
//format = MediaFormat.createVideoFormat();
// Perhaps just set MIME type
//format = new MediaFormat();
//format.setString(MediaFormat.KEY_MIME, payloadFormat.mimeType);
break;
}
}
return format;
}
示例4: Configuration
import android.media.MediaFormat; //导入方法依赖的package包/类
public Configuration(int width,int height){
mAudioFormat=MediaFormat.createAudioFormat("audio/mp4a-latm",48000,2);
mAudioFormat.setInteger(MediaFormat.KEY_BIT_RATE,128000);
mAudioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
mVideoFormat=MediaFormat.createVideoFormat("video/avc",width,height);
mVideoFormat.setInteger(MediaFormat.KEY_FRAME_RATE,24);
mVideoFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL,1);
mVideoFormat.setInteger(MediaFormat.KEY_BIT_RATE,width*height*5);
mVideoFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT,MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
}
示例5: getAudioMediaCodec
import android.media.MediaFormat; //导入方法依赖的package包/类
@TargetApi(18)
public static MediaCodec getAudioMediaCodec(){
MediaFormat format = MediaFormat.createAudioFormat(
Options.getInstance().audio.mime,
Options.getInstance().audio.frequency,
Options.getInstance().audio.channelCount);
if(Options.getInstance().audio.mime.equals(Options.DEFAULT_MIME)) {
format.setInteger(MediaFormat.KEY_AAC_PROFILE, Options.getInstance().audio.aacProfile);
}
format.setInteger(MediaFormat.KEY_BIT_RATE, Options.getInstance().audio.maxBps * 1024);
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, Options.getInstance().audio.frequency);
int maxInputSize = getRecordBufferSize();
format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, Options.getInstance().audio.channelCount);
MediaCodec mediaCodec = null;
try {
mediaCodec = MediaCodec.createEncoderByType(Options.getInstance().audio.mime);
mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
} catch (Exception e) {
e.printStackTrace();
if (mediaCodec != null) {
mediaCodec.stop();
mediaCodec.release();
mediaCodec = null;
}
}
return mediaCodec;
}
示例6: createAudioOutputFormat
import android.media.MediaFormat; //导入方法依赖的package包/类
@Override
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
if (mAudioBitrate == AUDIO_BITRATE_AS_IS || mAudioChannels == AUDIO_CHANNELS_AS_IS) return null;
// Use original sample rate, as resampling is not supported yet.
final MediaFormat format = MediaFormat.createAudioFormat(MediaFormatExtraConstants.MIMETYPE_AUDIO_AAC,
inputFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE), mAudioChannels);
format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
format.setInteger(MediaFormat.KEY_BIT_RATE, mAudioBitrate);
return format;
}
示例7: createAudioMediaFormat
import android.media.MediaFormat; //导入方法依赖的package包/类
public MediaFormat createAudioMediaFormat() {
MediaFormat format = MediaFormat.createAudioFormat(audioMIME, samplingRate, 2);
format.setInteger(MediaFormat.KEY_BIT_RATE, audioBitRate);
format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, audioBufferSize);
return format;
}
示例8: createAudioFormat
import android.media.MediaFormat; //导入方法依赖的package包/类
/**
* 创建音频MediaFormat[aac]
*
* @param sampleRate 采样率
* @param channelMask 声道
* @param channelCount 声道数
* @return
*/
public static MediaFormat createAudioFormat(int sampleRate, int channelMask, int channelCount) {
MediaFormat format = MediaFormat.createAudioFormat(MIME_TYPE_AAC, sampleRate, channelCount);
format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
// 声道
format.setInteger(MediaFormat.KEY_CHANNEL_MASK, channelMask);
// 声道数
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, channelCount);
// 音频bit率
format.setInteger(MediaFormat.KEY_BIT_RATE, AUDIO_BIT_RATE);
return format;
}
示例9: prepare
import android.media.MediaFormat; //导入方法依赖的package包/类
public void prepare(YXMuxerWrapper muxerWrapper) throws IOException {
mMuxer = muxerWrapper;
mBufferInfo = new MediaCodec.BufferInfo();
mAudioEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
mAudioFormat = MediaFormat.createAudioFormat(MIME_TYPE, SAMPLE_RATE, CHANNEL);
mAudioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectHE);
mAudioFormat.setInteger(MediaFormat.KEY_CHANNEL_MASK, AudioFormat.CHANNEL_IN_STEREO);
mAudioFormat.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
mAudioFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, CHANNEL);
mAudioFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 8192);
mAudioEncoder.configure(mAudioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
}
示例10: convertAudioConfigToFormat
import android.media.MediaFormat; //导入方法依赖的package包/类
protected MediaFormat convertAudioConfigToFormat(MediaConfig.Audio config){
MediaFormat format=MediaFormat.createAudioFormat(config.mime,config.sampleRate,config.channelCount);
format.setInteger(MediaFormat.KEY_BIT_RATE,config.bitrate);
format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
return format;
}