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


Java MediaExtractor.seekTo方法代码示例

本文整理汇总了Java中android.media.MediaExtractor.seekTo方法的典型用法代码示例。如果您正苦于以下问题:Java MediaExtractor.seekTo方法的具体用法?Java MediaExtractor.seekTo怎么用?Java MediaExtractor.seekTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaExtractor的用法示例。


在下文中一共展示了MediaExtractor.seekTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verifySamplesMatch

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * Uses 2 MediaExtractor, seeking to the same position, reads the sample and
 * makes sure the samples match.
 */
private void verifySamplesMatch(int srcMedia, String testMediaPath,
                                int seekToUs) throws IOException {
    AssetFileDescriptor testFd = mResources.openRawResourceFd(srcMedia);
    MediaExtractor extractorSrc = new MediaExtractor();
    extractorSrc.setDataSource(testFd.getFileDescriptor(),
            testFd.getStartOffset(), testFd.getLength());
    int trackCount = extractorSrc.getTrackCount();
    MediaExtractor extractorTest = new MediaExtractor();
    extractorTest.setDataSource(testMediaPath);
    assertEquals("wrong number of tracks", trackCount,
            extractorTest.getTrackCount());
    // Make sure the format is the same and select them
    for (int i = 0; i < trackCount; i++) {
        MediaFormat formatSrc = extractorSrc.getTrackFormat(i);
        MediaFormat formatTest = extractorTest.getTrackFormat(i);
        String mimeIn = formatSrc.getString(MediaFormat.KEY_MIME);
        String mimeOut = formatTest.getString(MediaFormat.KEY_MIME);
        if (!(mimeIn.equals(mimeOut))) {
            fail("format didn't match on track No." + i +
                    formatSrc.toString() + "\n" + formatTest.toString());
        }
        extractorSrc.selectTrack(i);
        extractorTest.selectTrack(i);
    }
    // Pick a time and try to compare the frame.
    extractorSrc.seekTo(seekToUs, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
    extractorTest.seekTo(seekToUs, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
    int bufferSize = MAX_SAMPLE_SIZE;
    ByteBuffer byteBufSrc = ByteBuffer.allocate(bufferSize);
    ByteBuffer byteBufTest = ByteBuffer.allocate(bufferSize);
    extractorSrc.readSampleData(byteBufSrc, 0);
    extractorTest.readSampleData(byteBufTest, 0);
    if (!(byteBufSrc.equals(byteBufTest))) {
        fail("byteBuffer didn't match");
    }
}
 
开发者ID:binkery,项目名称:allinone,代码行数:41,代码来源:MediaMuxerTest.java

示例2: verifySamplesMatch

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * Uses 2 MediaExtractor, seeking to the same position, reads the sample and
 * makes sure the samples match.
 */
private void verifySamplesMatch(int srcMedia, String testMediaPath,
        int seekToUs) throws IOException {
    AssetFileDescriptor testFd = mResources.openRawResourceFd(srcMedia);
    MediaExtractor extractorSrc = new MediaExtractor();
    extractorSrc.setDataSource(testFd.getFileDescriptor(),
            testFd.getStartOffset(), testFd.getLength());
    int trackCount = extractorSrc.getTrackCount();
    MediaExtractor extractorTest = new MediaExtractor();
    extractorTest.setDataSource(testMediaPath);
    assertEquals("wrong number of tracks", trackCount,
            extractorTest.getTrackCount());
    // Make sure the format is the same and select them
    for (int i = 0; i < trackCount; i++) {
        MediaFormat formatSrc = extractorSrc.getTrackFormat(i);
        MediaFormat formatTest = extractorTest.getTrackFormat(i);
        String mimeIn = formatSrc.getString(MediaFormat.KEY_MIME);
        String mimeOut = formatTest.getString(MediaFormat.KEY_MIME);
        if (!(mimeIn.equals(mimeOut))) {
            fail("format didn't match on track No." + i +
                    formatSrc.toString() + "\n" + formatTest.toString());
        }
        extractorSrc.selectTrack(i);
        extractorTest.selectTrack(i);
    }
    // Pick a time and try to compare the frame.
    extractorSrc.seekTo(seekToUs, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
    extractorTest.seekTo(seekToUs, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
    int bufferSize = MAX_SAMPLE_SIZE;
    ByteBuffer byteBufSrc = ByteBuffer.allocate(bufferSize);
    ByteBuffer byteBufTest = ByteBuffer.allocate(bufferSize);
    extractorSrc.readSampleData(byteBufSrc, 0);
    extractorTest.readSampleData(byteBufTest, 0);
    if (!(byteBufSrc.equals(byteBufTest))) {
        fail("byteBuffer didn't match");
    }
}
 
开发者ID:xu6148152,项目名称:binea_project_for_android,代码行数:41,代码来源:MediaMuxerTest.java

示例3: readAndWriteTrack

import android.media.MediaExtractor; //导入方法依赖的package包/类
@TargetApi(16)
private long readAndWriteTrack(final MessageObject messageObject, MediaExtractor extractor, MP4Builder mediaMuxer, MediaCodec.BufferInfo info, long start, long end, File file, boolean isAudio) throws Exception {
    int trackIndex = selectTrack(extractor, isAudio);
    if (trackIndex >= 0) {
        extractor.selectTrack(trackIndex);
        MediaFormat trackFormat = extractor.getTrackFormat(trackIndex);
        int muxerTrackIndex = mediaMuxer.addTrack(trackFormat, isAudio);
        int maxBufferSize = trackFormat.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE);
        boolean inputDone = false;
        if (start > 0) {
            extractor.seekTo(start, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
        } else {
            extractor.seekTo(0, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
        }
        ByteBuffer buffer = ByteBuffer.allocateDirect(maxBufferSize);
        long startTime = -1;

        checkConversionCanceled();
        long lastTimestamp = -100;

        while (!inputDone) {
            checkConversionCanceled();

            boolean eof = false;
            int index = extractor.getSampleTrackIndex();
            if (index == trackIndex) {
                info.size = extractor.readSampleData(buffer, 0);
                if (info.size >= 0) {
                    info.presentationTimeUs = extractor.getSampleTime();
                } else {
                    info.size = 0;
                    eof = true;
                }

                if (info.size > 0 && !eof) {
                    if (start > 0 && startTime == -1) {
                        startTime = info.presentationTimeUs;
                    }
                    if (end < 0 || info.presentationTimeUs < end) {
                        if (info.presentationTimeUs > lastTimestamp) {
                            info.offset = 0;
                            info.flags = extractor.getSampleFlags();
                            if (mediaMuxer.writeSampleData(muxerTrackIndex, buffer, info, isAudio)) {
                                didWriteData(messageObject, file, false, false);
                            }
                        }
                        lastTimestamp = info.presentationTimeUs;
                    } else {
                        eof = true;
                    }
                }
                if (!eof) {
                    extractor.advance();
                }
            } else if (index == -1) {
                eof = true;
            } else {
                extractor.advance();
            }
            if (eof) {
                inputDone = true;
            }
        }

        extractor.unselectTrack(trackIndex);
        return startTime;
    }
    return -1;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:70,代码来源:MediaController.java

示例4: readAndWriteTrack

import android.media.MediaExtractor; //导入方法依赖的package包/类
@TargetApi(16)
private long readAndWriteTrack(MediaExtractor extractor, MP4Builder mediaMuxer, MediaCodec.BufferInfo info, long start, long end, File file, boolean isAudio) throws Exception {
    int trackIndex = selectTrack(extractor, isAudio);
    if (trackIndex >= 0) {
        extractor.selectTrack(trackIndex);
        MediaFormat trackFormat = extractor.getTrackFormat(trackIndex);
        int muxerTrackIndex = mediaMuxer.addTrack(trackFormat, isAudio);
        int maxBufferSize = trackFormat.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE);
        boolean inputDone = false;
        if (start > 0) {
            extractor.seekTo(start, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
        } else {
            extractor.seekTo(0, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
        }
        ByteBuffer buffer = ByteBuffer.allocateDirect(maxBufferSize);
        long startTime = -1;

        while (!inputDone) {

            boolean eof = false;
            int index = extractor.getSampleTrackIndex();
            if (index == trackIndex) {
                info.size = extractor.readSampleData(buffer, 0);

                if (info.size < 0) {
                    info.size = 0;
                    eof = true;
                } else {
                    info.presentationTimeUs = extractor.getSampleTime();
                    if (start > 0 && startTime == -1) {
                        startTime = info.presentationTimeUs;
                    }
                    if (end < 0 || info.presentationTimeUs < end) {
                        info.offset = 0;
                        info.flags = extractor.getSampleFlags();
                        if (mediaMuxer.writeSampleData(muxerTrackIndex, buffer, info, isAudio)) {
                            // didWriteData(messageObject, file, false, false);
                        }
                        extractor.advance();
                    } else {
                        eof = true;
                    }
                }
            } else if (index == -1) {
                eof = true;
            }
            if (eof) {
                inputDone = true;
            }
        }

        extractor.unselectTrack(trackIndex);
        return startTime;
    }
    return -1;
}
 
开发者ID:fishwjy,项目名称:VideoCompressor,代码行数:57,代码来源:VideoController.java

示例5: feedClipToEncoder

import android.media.MediaExtractor; //导入方法依赖的package包/类
private void feedClipToEncoder( SamplerClip clip ) {

      mLastSampleTime = 0;

      MediaCodec decoder = null;

      MediaExtractor extractor = setupExtractorForClip(clip);
      
      if(extractor == null ) {
         return;
      }
      
      int trackIndex = getVideoTrackIndex(extractor);
      extractor.selectTrack( trackIndex );

      MediaFormat clipFormat = extractor.getTrackFormat( trackIndex );

      if ( clip.getStartTime() != -1 ) {
         extractor.seekTo( clip.getStartTime() * 1000, MediaExtractor.SEEK_TO_PREVIOUS_SYNC );
         clip.setStartTime( extractor.getSampleTime() / 1000 );
      }
      
      try {
         decoder = MediaCodec.createDecoderByType( MediaHelper.MIME_TYPE_AVC );
         mOutputSurface = new OutputSurface();

         decoder.configure( clipFormat, mOutputSurface.getSurface(), null, 0 );
         decoder.start();

         resampleVideo( extractor, decoder, clip );

      } finally {

         if ( mOutputSurface != null ) {
            mOutputSurface.release();
         }
         if ( decoder != null ) {
            decoder.stop();
            decoder.release();
         }

         if ( extractor != null ) {
            extractor.release();
            extractor = null;
         }
      }
   }
 
开发者ID:hoolrory,项目名称:AndroidVideoSamples,代码行数:48,代码来源:VideoResampler.java


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