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


Java MediaExtractor.selectTrack方法代码示例

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


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

示例1: selectTrack

import android.media.MediaExtractor; //导入方法依赖的package包/类
private MediaFormat selectTrack(MediaExtractor extractor) {
    int trackCount = extractor.getTrackCount();
    Log.d(TAG, "trackCount :" + trackCount);

    MediaFormat format;
    for (int i = 0; i < trackCount; i++) {
        extractor.selectTrack(i);
        format = extractor.getTrackFormat(i);
        Log.d(TAG, "Track media format :" + format.toString());

        String mime = format.getString(MediaFormat.KEY_MIME);
        if (mime.startsWith("video/")) {
            return format;
        }
    }

    return null;
}
 
开发者ID:ficklerobot,项目名称:grid-video-viewer,代码行数:19,代码来源:DecodeThread.java

示例2: initExtractor

import android.media.MediaExtractor; //导入方法依赖的package包/类
public boolean initExtractor(String filePath) throws IOException {
  decoding = false;
  audioExtractor = new MediaExtractor();
  audioExtractor.setDataSource(filePath);
  for (int i = 0; i < audioExtractor.getTrackCount() && !mime.startsWith("audio/"); i++) {
    audioFormat = audioExtractor.getTrackFormat(i);
    mime = audioFormat.getString(MediaFormat.KEY_MIME);
    if (mime.startsWith("audio/")) {
      audioExtractor.selectTrack(i);
    } else {
      audioFormat = null;
    }
  }
  if (audioFormat != null && mime.equals("audio/mp4a-latm")) {
    isStereo = (audioFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT) == 2);
    sampleRate = audioFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
    return true;
    //audio decoder not supported
  } else {
    mime = "";
    audioFormat = null;
    return false;
  }
}
 
开发者ID:pedroSG94,项目名称:rtmp-rtsp-stream-client-java,代码行数:25,代码来源:AudioDecoder.java

示例3: initExtractor

import android.media.MediaExtractor; //导入方法依赖的package包/类
public boolean initExtractor(String filePath) throws IOException {
  decoding = false;
  videoExtractor = new MediaExtractor();
  videoExtractor.setDataSource(filePath);
  for (int i = 0; i < videoExtractor.getTrackCount() && !mime.startsWith("video/"); i++) {
    videoFormat = videoExtractor.getTrackFormat(i);
    mime = videoFormat.getString(MediaFormat.KEY_MIME);
    if (mime.startsWith("video/")) {
      videoExtractor.selectTrack(i);
    } else {
      videoFormat = null;
    }
  }
  if (videoFormat != null && mime.equals("video/avc")) {
    width = videoFormat.getInteger(MediaFormat.KEY_WIDTH);
    height = videoFormat.getInteger(MediaFormat.KEY_HEIGHT);
    return true;
    //video decoder not supported
  } else {
    mime = "";
    videoFormat = null;
    return false;
  }
}
 
开发者ID:pedroSG94,项目名称:rtmp-rtsp-stream-client-java,代码行数:25,代码来源:VideoDecoder.java

示例4: concatVideoListFromMediaCodec

import android.media.MediaExtractor; //导入方法依赖的package包/类
private static void concatVideoListFromMediaCodec(List<String> pathList,
                                                  String destinationVideoFilePath, int videoRotation,
                                                  ConcatMediaCallback concatMediaCallback) throws IOException {
  MediaExtractor extractor = new MediaExtractor();
  MediaFormat format = null;
  extractor.setDataSource(pathList.get(0));
  int numTracks = extractor.getTrackCount();
  // find and select the first audio track present in the file.
  for (int i = 0; i < numTracks; i++) {
    format = extractor.getTrackFormat(i);
    if (format.getString(MediaFormat.KEY_MIME).startsWith("audio/")) {
      extractor.selectTrack(i);
      break;
    }
  }
  MediaCodec mediaCodec = MediaCodec.createDecoderByType(format.getString(MediaFormat.KEY_MIME));
  mediaCodec.configure(format, null, null, 0);
  mediaCodec.start();
}
 
开发者ID:XueyanLiu,项目名称:miku,代码行数:20,代码来源:VideoUtils.java

示例5: initMediaExtractor

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * Initialize a MediaExctractor if needed
 * @throws IOException
 */
private void initMediaExtractor() throws IOException{
    String filePath = Environment.getExternalStorageDirectory().getPath() + "/rpi960mal810.h264";
    //String filePath = "/storage/sdcard/rpi960mal810.h264";
    //String filePath = Environment.getExternalStorageDirectory().getPath() + "/somefile2.264"; //???
    //String filePath = "/storage/external_SD/movies/scut1.avi"; //???
    //String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/cat.h264";
    //String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/ravi2.264";
    //String filePath = Environment.getExternalStorageDirectory().getPath() + "/testfile.264";
    //String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/cat90.h264";

    File f = new File(filePath);
    boolean ext =  f.exists();


    mediaExtractor = new MediaExtractor();
    mediaExtractor.setDataSource(filePath);
    int trackCount = mediaExtractor.getTrackCount();
    if(trackCount != 1){
       // throw new RuntimeException("TrackCount = " + trackCount + ". Only Single Track is supported");
    }
    mediaExtractor.selectTrack(0);
}
 
开发者ID:HaBaLeS,项目名称:sac-fpv,代码行数:27,代码来源:H264DecodeThread.java

示例6: initMediaExtractor

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * Initialize a MediaExctractor if needed
 * @throws IOException
 */
private void initMediaExtractor() throws IOException{
    String filePath = Environment.getExternalStorageDirectory().getPath() + "/rpi960mal810.h264";
    //String filePath = "/storage/sdcard/rpi960mal810.h264";
    //String filePath = Environment.getExternalStorageDirectory().getPath() + "/somefile2.264"; //???
    //String filePath = "/storage/external_SD/movies/scut1.avi"; //???
    //String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/cat.h264";
    //String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/ravi2.264";
    //String filePath = Environment.getExternalStorageDirectory().getPath() + "/testfile.264";
    //String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/cat90.h264";

    File f = new File(filePath);
    boolean ext =  f.exists();


    mediaExtractor = new MediaExtractor();
    mediaExtractor.setDataSource(filePath);
    int trackCount = mediaExtractor.getTrackCount();
    if(trackCount != 1){
        // throw new RuntimeException("TrackCount = " + trackCount + ". Only Single Track is supported");
    }
    mediaExtractor.selectTrack(0);
}
 
开发者ID:HaBaLeS,项目名称:sac-fpv,代码行数:27,代码来源:H264DecodeThreadFileBasedLogging.java

示例7: MP4Encorder

import android.media.MediaExtractor; //导入方法依赖的package包/类
public MP4Encorder(Session session){
    mediaExtractor = new MediaExtractor();
    try {
        mediaExtractor.setDataSource(session.getVideoPath());
    } catch (IOException e) {
        e.printStackTrace();
    }
    for(int i = 0; i < mediaExtractor.getTrackCount(); i++) {
        MediaFormat format = mediaExtractor.getTrackFormat(i);
        String mime = format.getString(MediaFormat.KEY_MIME);
        if (!mime.startsWith("video/")) {
            continue;
        }
        framerate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
        mediaExtractor.selectTrack(i);
        session.getVideoQuality().setmFrameRate(framerate);
    }
}
 
开发者ID:lijundacom,项目名称:AndroidRTSPLib2,代码行数:19,代码来源:MP4Encorder.java

示例8: prepare

import android.media.MediaExtractor; //导入方法依赖的package包/类
public void prepare(String path) {
    mExtractor = new MediaExtractor();
    try {
        mExtractor.setDataSource(path);
    } catch (IOException e) {
        e.printStackTrace();
    }
    int tracks = mExtractor.getTrackCount();
    for (int i = 0; i < tracks; i++) {
        MediaFormat format = mExtractor.getTrackFormat(i);
        String mime = format.getString(MediaFormat.KEY_MIME);
        Logs.i(TAG, "mime = " + mime);
    }
    mExtractor.selectTrack(0);
    mAudioBuffer = ByteBuffer.allocate(1024);

    next();;
}
 
开发者ID:binkery,项目名称:allinone,代码行数:19,代码来源:AudioEncoder.java

示例9: prepareAudio

import android.media.MediaExtractor; //导入方法依赖的package包/类
private MediaExtractor prepareAudio(String path) {
    MediaExtractor mExtractor = new MediaExtractor();
    try {
        mExtractor.setDataSource(path);
    } catch (IOException e) {
        e.printStackTrace();
    }
    int tracks = mExtractor.getTrackCount();
    for (int i = 0; i < tracks; i++) {
        MediaFormat format = mExtractor.getTrackFormat(i);
        String mime = format.getString(MediaFormat.KEY_MIME);
        Logs.i(TAG, "mime = " + mime);
    }

    mExtractor.selectTrack(0);
    return mExtractor;
}
 
开发者ID:binkery,项目名称:allinone,代码行数:18,代码来源:Maker.java

示例10: internal_prepare_video

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * @param src_file
 * @return first video track index, -1 if not found
 */
protected int internal_prepare_video(final String source_path) {
	int trackindex = -1;
	mVideoMediaExtractor = new MediaExtractor();
	try {
		mVideoMediaExtractor.setDataSource(source_path);
		trackindex = selectTrack(mVideoMediaExtractor, "video/");
		if (trackindex >= 0) {
			mVideoMediaExtractor.selectTrack(trackindex);
	        final MediaFormat format = mVideoMediaExtractor.getTrackFormat(trackindex);
        	mVideoWidth = format.getInteger(MediaFormat.KEY_WIDTH);
        	mVideoHeight = format.getInteger(MediaFormat.KEY_HEIGHT);
        	mDuration = format.getLong(MediaFormat.KEY_DURATION);

			if (DEBUG) Log.v(TAG, String.format("format:size(%d,%d),duration=%d,bps=%d,framerate=%f,rotation=%d",
				mVideoWidth, mVideoHeight, mDuration, mBitrate, mFrameRate, mRotation));
		}
	} catch (final IOException e) {
	}
	return trackindex;
}
 
开发者ID:saki4510t,项目名称:AudioVideoPlayerSample,代码行数:25,代码来源:MediaMoviePlayer.java

示例11: internal_prepare_video

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * @param src_file
 * @return first video track index, -1 if not found
 */
protected int internal_prepare_video(final String source_file) {
	int trackindex = -1;
	mVideoMediaExtractor = new MediaExtractor();
	try {
		mVideoMediaExtractor.setDataSource(source_file);
		trackindex = selectTrack(mVideoMediaExtractor, "video/");
		if (trackindex >= 0) {
			mVideoMediaExtractor.selectTrack(trackindex);
	        final MediaFormat format = mVideoMediaExtractor.getTrackFormat(trackindex);
        	mVideoWidth = format.getInteger(MediaFormat.KEY_WIDTH);
        	mVideoHeight = format.getInteger(MediaFormat.KEY_HEIGHT);
        	mDuration = format.getLong(MediaFormat.KEY_DURATION);

			if (DEBUG) Log.v(TAG, String.format("format:size(%d,%d),duration=%d,bps=%d,framerate=%f,rotation=%d",
				mVideoWidth, mVideoHeight, mDuration, mBitrate, mFrameRate, mRotation));
		}
	} catch (final IOException e) {
	}
	return trackindex;
}
 
开发者ID:saki4510t,项目名称:AudioVideoPlayerSample,代码行数:25,代码来源:MediaVideoPlayer.java

示例12: internal_prepare_video

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * @param source
 * @return first video track index, -1 if not found
 */
@SuppressLint("NewApi")
protected int internal_prepare_video(final Object source) {
	int trackindex = -1;
	mVideoMediaExtractor = new MediaExtractor();
	try {
		if (source instanceof String) {
			mVideoMediaExtractor.setDataSource((String)source);
		} else if (source instanceof AssetFileDescriptor) {
			if (BuildCheck.isAndroid7()) {
				mVideoMediaExtractor.setDataSource((AssetFileDescriptor)source);
			} else {
				mVideoMediaExtractor.setDataSource(((AssetFileDescriptor)source).getFileDescriptor());
			}
		} else {
			// ここには来ないけど
			throw new IllegalArgumentException("unknown source type:source=" + source);
		}
		trackindex = selectTrack(mVideoMediaExtractor, "video/");
		if (trackindex >= 0) {
			mVideoMediaExtractor.selectTrack(trackindex);
	        final MediaFormat format = mVideoMediaExtractor.getTrackFormat(trackindex);
        	mVideoWidth = format.getInteger(MediaFormat.KEY_WIDTH);
        	mVideoHeight = format.getInteger(MediaFormat.KEY_HEIGHT);
        	mDuration = format.getLong(MediaFormat.KEY_DURATION);

			if (DEBUG) Log.v(TAG, String.format("format:size(%d,%d),duration=%d,bps=%d,framerate=%f,rotation=%d",
				mVideoWidth, mVideoHeight, mDuration, mBitrate, mFrameRate, mRotation));
		}
	} catch (final IOException e) {
	}
	return trackindex;
}
 
开发者ID:saki4510t,项目名称:libcommon,代码行数:37,代码来源:MediaMoviePlayer.java

示例13: 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

示例14: 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

示例15: setupExtractor

import android.media.MediaExtractor; //导入方法依赖的package包/类
private void setupExtractor() {
   mExtractor = new MediaExtractor();
   try {
      mExtractor.setDataSource( mUri.toString() );
   } catch ( IOException e ) {
      e.printStackTrace();
   }

   int videoIndex = 0;

   for ( int trackIndex = 0; trackIndex < mExtractor.getTrackCount(); trackIndex++ ) {
      MediaFormat format = mExtractor.getTrackFormat( trackIndex );

      String mime = format.getString( MediaFormat.KEY_MIME );
      if ( mime != null ) {
         if ( mime.equals( "video/avc" ) ) {
            mExtractor.selectTrack( trackIndex );
            videoIndex = trackIndex;
            break;
         }
      }
   }

   mDecoder = MediaCodec.createDecoderByType( "video/avc" );
   mDecoder.configure( mExtractor.getTrackFormat( videoIndex ), mSurface, null, 0 );
   mDecoder.start();

   mInfo = new BufferInfo();

   mInputBuffers = mDecoder.getInputBuffers();
   mOutputBuffers = mDecoder.getOutputBuffers();
}
 
开发者ID:hoolrory,项目名称:AndroidVideoSamples,代码行数:33,代码来源:MediaCodecDecodeController.java


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