当前位置: 首页>>代码示例>>Java>>正文


Java MediaFormat.createAudioFormat方法代码示例

本文整理汇总了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;
}
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:26,代码来源:MediaCodecUtils.java

示例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;
        }
    }
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:21,代码来源:AudioEncoderCore.java

示例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;
}
 
开发者ID:devinbrown7,项目名称:streaminglib,代码行数:26,代码来源:MediaFormatHelper.java

示例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);
}
 
开发者ID:aiyaapp,项目名称:AAVT,代码行数:12,代码来源:CameraRecorder.java

示例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;
}
 
开发者ID:wuyisheng,项目名称:libRtmp,代码行数:30,代码来源:AndroidUntil.java

示例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;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:12,代码来源:Android720pFormatStrategy.java

示例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;
}
 
开发者ID:ChillingVan,项目名称:AndroidInstantVideo,代码行数:9,代码来源:StreamPublisher.java

示例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;
}
 
开发者ID:uestccokey,项目名称:EZFilter,代码行数:20,代码来源:MediaUtil.java

示例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);
}
 
开发者ID:sunshinecoast,项目名称:ScreenRecordCaptureMaster,代码行数:14,代码来源:YXAudioEncoder.java

示例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;
}
 
开发者ID:aiyaapp,项目名称:AAVT,代码行数:7,代码来源:SoundRecorder.java


注:本文中的android.media.MediaFormat.createAudioFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。