當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaExtractor類代碼示例

本文整理匯總了Java中android.media.MediaExtractor的典型用法代碼示例。如果您正苦於以下問題:Java MediaExtractor類的具體用法?Java MediaExtractor怎麽用?Java MediaExtractor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MediaExtractor類屬於android.media包,在下文中一共展示了MediaExtractor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFirstVideoAndAudioTrack

import android.media.MediaExtractor; //導入依賴的package包/類
public static TrackResult getFirstVideoAndAudioTrack(MediaExtractor extractor) {
    TrackResult trackResult = new TrackResult();
    trackResult.mVideoTrackIndex = -1;
    trackResult.mAudioTrackIndex = -1;
    int trackCount = extractor.getTrackCount();
    for (int i = 0; i < trackCount; i++) {
        MediaFormat format = extractor.getTrackFormat(i);
        String mime = format.getString(MediaFormat.KEY_MIME);
        if (trackResult.mVideoTrackIndex < 0 && mime.startsWith("video/")) {
            trackResult.mVideoTrackIndex = i;
            trackResult.mVideoTrackMime = mime;
            trackResult.mVideoTrackFormat = format;
        } else if (trackResult.mAudioTrackIndex < 0 && mime.startsWith("audio/")) {
            trackResult.mAudioTrackIndex = i;
            trackResult.mAudioTrackMime = mime;
            trackResult.mAudioTrackFormat = format;
        }
        if (trackResult.mVideoTrackIndex >= 0 && trackResult.mAudioTrackIndex >= 0) break;
    }
    if (trackResult.mVideoTrackIndex < 0 || trackResult.mAudioTrackIndex < 0) {
        throw new IllegalArgumentException("extractor does not contain video and/or audio tracks.");
    }
    return trackResult;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:25,代碼來源:MediaExtractorUtils.java

示例2: startSeeking

import android.media.MediaExtractor; //導入依賴的package包/類
@Override
public void startSeeking() throws IOException {
    super.startSeeking();
    Log.d(TAG, "start seeking state is: " + mState);
    if (mState == STATE_SEEKING)
        return;
    prepare();
    setState(STATE_SEEKING);
    mInputDone = mOutputDone = false;
    mSeekDirection = SEEK_DIRECTION_FORWARD;
    mMediaCodec.start();
    mSeekTargetTime = mExtractor.getSampleTime();
    mExtractor.seekTo(mSeekTargetTime, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
    mIsSeeking = true;
    new Thread(mSeekRunnable, getClass().getSimpleName()).start();
}
 
開發者ID:Tai-Kimura,項目名稱:VideoApplication,代碼行數:17,代碼來源:VideoDecoder.java

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

示例4: selectTrack

import android.media.MediaExtractor; //導入依賴的package包/類
@TargetApi(16)
private int selectTrack(MediaExtractor extractor, boolean audio) {
    int numTracks = extractor.getTrackCount();
    for (int i = 0; i < numTracks; i++) {
        MediaFormat format = extractor.getTrackFormat(i);
        String mime = format.getString(MediaFormat.KEY_MIME);
        if (audio) {
            if (mime.startsWith("audio/")) {
                return i;
            }
        } else {
            if (mime.startsWith("video/")) {
                return i;
            }
        }
    }
    return -5;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:19,代碼來源:MediaController.java

示例5: drainExtractor

import android.media.MediaExtractor; //導入依賴的package包/類
private int drainExtractor(long timeoutUs) {
    if (mIsExtractorEOS) return DRAIN_STATE_NONE;
    int trackIndex = mExtractor.getSampleTrackIndex();
    if (trackIndex >= 0 && trackIndex != mTrackIndex) {
        return DRAIN_STATE_NONE;
    }

    final int result = mDecoder.dequeueInputBuffer(timeoutUs);
    if (result < 0) return DRAIN_STATE_NONE;
    if (trackIndex < 0) {
        mIsExtractorEOS = true;
        mDecoder.queueInputBuffer(result, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
        return DRAIN_STATE_NONE;
    }

    final int sampleSize = mExtractor.readSampleData(mDecoderBuffers.getInputBuffer(result), 0);
    final boolean isKeyFrame = (mExtractor.getSampleFlags() & MediaExtractor.SAMPLE_FLAG_SYNC) != 0;
    mDecoder.queueInputBuffer(result, 0, sampleSize, mExtractor.getSampleTime(), isKeyFrame ? MediaCodec.BUFFER_FLAG_SYNC_FRAME : 0);
    mExtractor.advance();
    return DRAIN_STATE_CONSUMED;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:22,代碼來源:AudioTrackTranscoder.java

示例6: drainExtractor

import android.media.MediaExtractor; //導入依賴的package包/類
private int drainExtractor(long timeoutUs) {
    if (mIsExtractorEOS) return DRAIN_STATE_NONE;
    int trackIndex = mExtractor.getSampleTrackIndex();
    if (trackIndex >= 0 && trackIndex != mTrackIndex) {
        return DRAIN_STATE_NONE;
    }
    int result = mDecoder.dequeueInputBuffer(timeoutUs);
    if (result < 0) return DRAIN_STATE_NONE;
    if (trackIndex < 0) {
        mIsExtractorEOS = true;
        mDecoder.queueInputBuffer(result, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
        return DRAIN_STATE_NONE;
    }
    int sampleSize = mExtractor.readSampleData(mDecoderInputBuffers[result], 0);
    boolean isKeyFrame = (mExtractor.getSampleFlags() & MediaExtractor.SAMPLE_FLAG_SYNC) != 0;
    mDecoder.queueInputBuffer(result, 0, sampleSize, mExtractor.getSampleTime(), isKeyFrame ? MediaCodec.BUFFER_FLAG_SYNC_FRAME : 0);
    mExtractor.advance();
    return DRAIN_STATE_CONSUMED;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:20,代碼來源:VideoTrackTranscoder.java

示例7: seekTo

import android.media.MediaExtractor; //導入依賴的package包/類
public void seekTo(long presentationTime) {
    synchronized (mDecoderSync) {
        if (mIsSeeking)
            return;
        Log.d(TAG, "seek diff:" + (presentationTime - mSeekTargetTime));
        mInputDone = mOutputDone = false;
        mSeekDirection = presentationTime >= mSeekTargetTime ? SEEK_DIRECTION_FORWARD : SEEK_DIRECTION_BACKWARD;
        if ((mSeekDirection == SEEK_DIRECTION_BACKWARD) || mSeekDirection == SEEK_DIRECTION_FORWARD && Math.abs(presentationTime - mLastSyncFrameTime) > mMaximumDifference) {
            mExtractor.seekTo(presentationTime, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
            mLastSyncFrameTime = mExtractor.getSampleTime();
        }
        mSeekTargetTime = presentationTime;
        mIsSeeking = true;
        mDecoderSync.notifyAll();
    }
}
 
開發者ID:Tai-Kimura,項目名稱:VideoApplication,代碼行數:17,代碼來源:VideoDecoder.java

示例8: readyExtractor

import android.media.MediaExtractor; //導入依賴的package包/類
/**
 * 現在のfilePathを使ってExtractorを作成する
 */
private boolean readyExtractor(String filePath) {
    boolean isOk = false;
    mBufferinfo = new MediaCodec.BufferInfo();

    try {
        mExtractor = new MediaExtractor();
        mExtractor.setDataSource(filePath);
        isOk = true;

    } catch (IOException e) {
        e.printStackTrace();
        Log.d(TAG, "Failed to setDataSource id:" + id);
        mVideoData = null;
    }

    return isOk;
}
 
開發者ID:ficklerobot,項目名稱:grid-video-viewer,代碼行數:21,代碼來源:DecodeThread.java

示例9: selectTrack

import android.media.MediaExtractor; //導入依賴的package包/類
/**
 * Selects the video track, if any.
 *
 * @return the track index, or -1 if no video track is found.
 */
private static int selectTrack(MediaExtractor extractor) {
    // Select the first video track we find, ignore the rest.
    int numTracks = extractor.getTrackCount();
    for (int i = 0; i < numTracks; i++) {
        MediaFormat format = extractor.getTrackFormat(i);
        String mime = format.getString(MediaFormat.KEY_MIME);
        if (mime.startsWith("video/")) {
            if (VERBOSE) {
                Log.d(TAG, "Extractor selected track " + i + " (" + mime + "): " + format);
            }
            return i;
        }
    }

    return -1;
}
 
開發者ID:AndyZhu1991,項目名稱:grafika,代碼行數:22,代碼來源:MoviePlayer.java

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

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

示例12: drainExtractor

import android.media.MediaExtractor; //導入依賴的package包/類
private int drainExtractor(long timeoutUs) {
    if (mIsExtractorEOS) return DRAIN_STATE_NONE;
    int trackIndex = mExtractor.getSampleTrackIndex();
    if (trackIndex >= 0 && trackIndex != mTrackIndex) {
        return DRAIN_STATE_NONE;
    }

    int result = mDecoder.dequeueInputBuffer(timeoutUs);
    if (result < 0) return DRAIN_STATE_NONE;
    if (trackIndex < 0) {
        mIsExtractorEOS = true;
        mDecoder.queueInputBuffer(result, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
        return DRAIN_STATE_NONE;
    }

    int sampleSize = mExtractor.readSampleData(MediaUtil.getInputBuffer(mDecoder, result), 0);
    boolean isKeyFrame = (mExtractor.getSampleFlags() & MediaExtractor.SAMPLE_FLAG_SYNC) != 0;
    mDecoder.queueInputBuffer(result, 0, sampleSize, mExtractor.getSampleTime(), isKeyFrame ? MediaCodec.BUFFER_FLAG_SYNC_FRAME : 0);
    mExtractor.advance();
    return DRAIN_STATE_CONSUMED;
}
 
開發者ID:uestccokey,項目名稱:EZFilter,代碼行數:22,代碼來源:AudioTrackTranscoder.java

示例13: drainExtractor

import android.media.MediaExtractor; //導入依賴的package包/類
private int drainExtractor(long timeoutUs) {
    if (mIsExtractorEOS) return DRAIN_STATE_NONE;
    int trackIndex = mExtractor.getSampleTrackIndex();
    if (trackIndex >= 0 && trackIndex != mTrackIndex) {
        return DRAIN_STATE_NONE;
    }

    int result = mDecoder.dequeueInputBuffer(timeoutUs);
    if (result < 0) return DRAIN_STATE_NONE;
    if (trackIndex < 0) {
        mIsExtractorEOS = true;
        mDecoder.queueInputBuffer(result, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
        return DRAIN_STATE_NONE;
    }

    int sampleSize = mExtractor.readSampleData(mDecoderInputBuffers[result], 0);
    boolean isKeyFrame = (mExtractor.getSampleFlags() & MediaExtractor.SAMPLE_FLAG_SYNC) != 0;
    mDecoder.queueInputBuffer(result, 0, sampleSize, mExtractor.getSampleTime(), isKeyFrame ? MediaCodec.BUFFER_FLAG_SYNC_FRAME : 0);
    mExtractor.advance();
    return DRAIN_STATE_CONSUMED;
}
 
開發者ID:uestccokey,項目名稱:EZFilter,代碼行數:22,代碼來源:VideoTrackTranscoder.java

示例14: retrieveFrameRate

import android.media.MediaExtractor; //導入依賴的package包/類
public int retrieveFrameRate() {
    MediaExtractor extractor = new MediaExtractor();
    int frameRate = -1;
    try {
        //Adjust data source as per the requirement if file, URI, etc.
        extractor.setDataSource(getPath());
        int numTracks = extractor.getTrackCount();
        for (int i = 0; i < numTracks; i++) {
            MediaFormat format = extractor.getTrackFormat(i);
            if (format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
                frameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        //Release stuff
        extractor.release();
    }
    return frameRate;
}
 
開發者ID:kollerlukas,項目名稱:Camera-Roll-Android-App,代碼行數:22,代碼來源:Video.java

示例15: getDuration

import android.media.MediaExtractor; //導入依賴的package包/類
/**
 * 獲取視頻信息
 *
 * @param url
 * @return
 */
public static long getDuration(String url) {
	try {
		MediaExtractor mediaExtractor = new MediaExtractor();
		mediaExtractor.setDataSource(url);
		int videoExt = TrackUtils.selectVideoTrack(mediaExtractor);
		if(videoExt == -1){
			videoExt = TrackUtils.selectAudioTrack(mediaExtractor);
			if(videoExt == -1){
				return 0;
			}
		}
		MediaFormat mediaFormat = mediaExtractor.getTrackFormat(videoExt);
		long res = mediaFormat.containsKey(MediaFormat.KEY_DURATION) ? mediaFormat.getLong(MediaFormat.KEY_DURATION) : 0;//時長
		mediaExtractor.release();
		return res;
	} catch (Exception e) {
		return 0;
	}
}
 
開發者ID:yangjie10930,項目名稱:EpMedia,代碼行數:26,代碼來源:VideoUitls.java


注:本文中的android.media.MediaExtractor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。