Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

13.10. MediaCodec

		
        try {
            MediaFormat format = MediaFormat.createAudioFormat("audio/mpeg", sampleRate, 1);
            format.setInteger(MediaFormat.KEY_BIT_RATE, 128000);
            format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 4096);
            int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
            int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
            decoder = MediaCodec.createDecoderByType("audio/mpeg");
            decoder.configure(format, null, null, 0);
            decoder.start();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }