Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop MediaCodec and lamemp3 Multi-segment Audio capture and splicing by Android

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

< audioExtractor.getTrackCount(); i++) { MediaFormat format = audioExtractor.getTrackFormat(i); String mime = format.getString(MediaFormat.KEY_MIME); if(mime.startsWith(AUDIO)){ d = format.getLong(MediaFormat.KEY_DURATION); audioExtractor.selectTrack(i); audioDecoder = MediaCodec.createDecoderByType(mime); audioDecoder.configure(format, null, null, 0); audioDecoder.start(); break; } } } catch (IOException e) { e.printStackTrace(); } MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); while (true) { extractorInputBuffer(audioExtractor, audioDecoder); int outIndex = audioDecoder.dequeueOutputBuffer(info, 50000); if (outIndex >

= 0) {ByteBuffer data = audioDecoder.getOutputBuffer (outIndex); if ((info.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG)! = 0) {info.size = 0;} if (info.size! = 0) {byte [] bytes = new byte [data.remaining ()] Data.get (bytes,0,bytes.length); data.clear (); try {pcmos.write (bytes);} catch (IOException e) {e.printStackTrace () } if (encoderListener! = null) {int progress = (int) (info.presentationTimeUs + startTime) * 50) / duration); encoderListener.onEncoder (progress);}} audioDecoder.releaseOutputBuffer (outIndex, false) } if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM)! = 0) {break;}} audioDecoder.stop (); audioDecoder.release (); audioExtractor.release (); return d;} private void extractorInputBuffer (MediaExtractor mediaExtractor, MediaCodec mediaCodec) {int inputIndex = mediaCodec.dequeueInputBuffer (50000) If (inputIndex > = 0) {ByteBuffer inputBuffer = mediaCodec.getInputBuffer (inputIndex); long sampleTime = mediaExtractor.getSampleTime (); int sampleSize = mediaExtractor.readSampleData (inputBuffer, 0); if (mediaExtractor.advance ()) {mediaCodec.queueInputBuffer (inputIndex, 0, sampleSize, sampleTime, 0) } else {if (sampleSize > 0) {mediaCodec.queueInputBuffer (inputIndex, 0, sampleSize, sampleTime, MediaCodec.BUFFER_FLAG_END_OF_STREAM);} else {mediaCodec.queueInputBuffer (inputIndex, 0,0,0, MediaCodec.BUFFER_FLAG_END_OF_STREAM) }} private int format (int fjingint [] fs) {if (f > = fs [0]) {return fs [0];} else if (f = fs [I]) {return fs [I];} return-1 The progress bar function of jni callback, 50 * / public void setProgress (long size,long total) {if (encoderListener! = null) {int progress = 50 + (int) ((total*50) / size); if (decoderHolder = = null) {encoderListener.onEncoder (progress) } else {encoderListener.onDecoder (decoderHolder,progress);}} public interface OnAudioEncoderListener {void onDecoder (AudioHolder decoderHolder,int progress); void onEncoder (int progress); void onOver (String path);}} use private AudioMerge audioMerge = new AudioMerge (); private List list = new ArrayList () AudioMerge.start (Environment.getExternalStorageDirectory (). GetAbsolutePath () + "/ HMSDK/test_merge.mp3", list); this is the end of the article on "how to develop MediaCodec and lamemp3 multi-segment audio capture and splicing by Android". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how Android develops MediaCodec and lamemp3 multi-segment audio interception and splicing". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report