當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。