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


Java MediaFormat.containsKey方法代碼示例

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


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

示例1: retrieveFrameRate

import android.media.MediaFormat; //導入方法依賴的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

示例2: getDuration

import android.media.MediaFormat; //導入方法依賴的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

示例3: onOutputFormatChanged

import android.media.MediaFormat; //導入方法依賴的package包/類
@Override
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat) {
  boolean hasCrop = outputFormat.containsKey(KEY_CROP_RIGHT)
      && outputFormat.containsKey(KEY_CROP_LEFT) && outputFormat.containsKey(KEY_CROP_BOTTOM)
      && outputFormat.containsKey(KEY_CROP_TOP);
  currentWidth = hasCrop
      ? outputFormat.getInteger(KEY_CROP_RIGHT) - outputFormat.getInteger(KEY_CROP_LEFT) + 1
      : outputFormat.getInteger(MediaFormat.KEY_WIDTH);
  currentHeight = hasCrop
      ? outputFormat.getInteger(KEY_CROP_BOTTOM) - outputFormat.getInteger(KEY_CROP_TOP) + 1
      : outputFormat.getInteger(MediaFormat.KEY_HEIGHT);
  currentPixelWidthHeightRatio = pendingPixelWidthHeightRatio;
  if (Util.SDK_INT >= 21) {
    // On API level 21 and above the decoder applies the rotation when rendering to the surface.
    // Hence currentUnappliedRotation should always be 0. For 90 and 270 degree rotations, we need
    // to flip the width, height and pixel aspect ratio to reflect the rotation that was applied.
    if (pendingRotationDegrees == 90 || pendingRotationDegrees == 270) {
      int rotatedHeight = currentWidth;
      currentWidth = currentHeight;
      currentHeight = rotatedHeight;
      currentPixelWidthHeightRatio = 1 / currentPixelWidthHeightRatio;
    }
  } else {
    // On API level 20 and below the decoder does not apply the rotation.
    currentUnappliedRotationDegrees = pendingRotationDegrees;
  }
  // Must be applied each time the output format changes.
  setVideoScalingMode(codec, scalingMode);
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:30,代碼來源:MediaCodecVideoRenderer.java

示例4: dequeueOutputBuffer

import android.media.MediaFormat; //導入方法依賴的package包/類
private DecodedOutputBuffer dequeueOutputBuffer(int dequeueTimeoutMs) {
  checkOnMediaCodecThread();
  if (decodeStartTimeMs.isEmpty()) {
    return null;
  }
  // Drain the decoder until receiving a decoded buffer or hitting
  // MediaCodec.INFO_TRY_AGAIN_LATER.
  final MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
  while (true) {
    final int result =
        mediaCodec.dequeueOutputBuffer(info, TimeUnit.MILLISECONDS.toMicros(dequeueTimeoutMs));
    switch (result) {
      case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED:
        outputBuffers = mediaCodec.getOutputBuffers();
        Logging.d(TAG, "Decoder output buffers changed: " + outputBuffers.length);
        if (hasDecodedFirstFrame) {
          throw new RuntimeException("Unexpected output buffer change event.");
        }
        break;
      case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED:
        MediaFormat format = mediaCodec.getOutputFormat();
        Logging.d(TAG, "Decoder format changed: " + format.toString());
        final int newWidth;
        final int newHeight;
        if (format.containsKey(FORMAT_KEY_CROP_LEFT) && format.containsKey(FORMAT_KEY_CROP_RIGHT)
            && format.containsKey(FORMAT_KEY_CROP_BOTTOM)
            && format.containsKey(FORMAT_KEY_CROP_TOP)) {
          newWidth = 1 + format.getInteger(FORMAT_KEY_CROP_RIGHT)
              - format.getInteger(FORMAT_KEY_CROP_LEFT);
          newHeight = 1 + format.getInteger(FORMAT_KEY_CROP_BOTTOM)
              - format.getInteger(FORMAT_KEY_CROP_TOP);
        } else {
          newWidth = format.getInteger(MediaFormat.KEY_WIDTH);
          newHeight = format.getInteger(MediaFormat.KEY_HEIGHT);
        }
        if (hasDecodedFirstFrame && (newWidth != width || newHeight != height)) {
          throw new RuntimeException("Unexpected size change. Configured " + width + "*" + height
              + ". New " + newWidth + "*" + newHeight);
        }
        width = newWidth;
        height = newHeight;

        if (!useSurface && format.containsKey(MediaFormat.KEY_COLOR_FORMAT)) {
          colorFormat = format.getInteger(MediaFormat.KEY_COLOR_FORMAT);
          Logging.d(TAG, "Color: 0x" + Integer.toHexString(colorFormat));
          if (!supportedColorList.contains(colorFormat)) {
            throw new IllegalStateException("Non supported color format: " + colorFormat);
          }
        }
        if (format.containsKey(FORMAT_KEY_STRIDE)) {
          stride = format.getInteger(FORMAT_KEY_STRIDE);
        }
        if (format.containsKey(FORMAT_KEY_SLICE_HEIGHT)) {
          sliceHeight = format.getInteger(FORMAT_KEY_SLICE_HEIGHT);
        }
        Logging.d(TAG, "Frame stride and slice height: " + stride + " x " + sliceHeight);
        stride = Math.max(width, stride);
        sliceHeight = Math.max(height, sliceHeight);
        break;
      case MediaCodec.INFO_TRY_AGAIN_LATER:
        return null;
      default:
        hasDecodedFirstFrame = true;
        TimeStamps timeStamps = decodeStartTimeMs.remove();
        long decodeTimeMs = SystemClock.elapsedRealtime() - timeStamps.decodeStartTimeMs;
        if (decodeTimeMs > MAX_DECODE_TIME_MS) {
          Logging.e(TAG, "Very high decode time: " + decodeTimeMs + "ms"
                  + ". Q size: " + decodeStartTimeMs.size()
                  + ". Might be caused by resuming H264 decoding after a pause.");
          decodeTimeMs = MAX_DECODE_TIME_MS;
        }
        return new DecodedOutputBuffer(result, info.offset, info.size,
            TimeUnit.MICROSECONDS.toMillis(info.presentationTimeUs), timeStamps.timeStampMs,
            timeStamps.ntpTimeStampMs, decodeTimeMs, SystemClock.elapsedRealtime());
    }
  }
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:78,代碼來源:MediaCodecVideoDecoder.java

示例5: reformat

import android.media.MediaFormat; //導入方法依賴的package包/類
private void reformat(MediaFormat format) {
  outputThreadChecker.checkIsOnValidThread();
  Logging.d(TAG, "Decoder format changed: " + format.toString());
  final int newWidth;
  final int newHeight;
  if (format.containsKey(MEDIA_FORMAT_KEY_CROP_LEFT)
      && format.containsKey(MEDIA_FORMAT_KEY_CROP_RIGHT)
      && format.containsKey(MEDIA_FORMAT_KEY_CROP_BOTTOM)
      && format.containsKey(MEDIA_FORMAT_KEY_CROP_TOP)) {
    newWidth = 1 + format.getInteger(MEDIA_FORMAT_KEY_CROP_RIGHT)
        - format.getInteger(MEDIA_FORMAT_KEY_CROP_LEFT);
    newHeight = 1 + format.getInteger(MEDIA_FORMAT_KEY_CROP_BOTTOM)
        - format.getInteger(MEDIA_FORMAT_KEY_CROP_TOP);
  } else {
    newWidth = format.getInteger(MediaFormat.KEY_WIDTH);
    newHeight = format.getInteger(MediaFormat.KEY_HEIGHT);
  }
  // Compare to existing width, height, and save values under the dimension lock.
  synchronized (dimensionLock) {
    if (hasDecodedFirstFrame && (width != newWidth || height != newHeight)) {
      stopOnOutputThread(new RuntimeException("Unexpected size change. Configured " + width + "*"
          + height + ". New " + newWidth + "*" + newHeight));
      return;
    }
    width = newWidth;
    height = newHeight;
  }

  // Note:  texture mode ignores colorFormat.  Hence, if the texture helper is non-null, skip
  // color format updates.
  if (surfaceTextureHelper == null && format.containsKey(MediaFormat.KEY_COLOR_FORMAT)) {
    colorFormat = format.getInteger(MediaFormat.KEY_COLOR_FORMAT);
    Logging.d(TAG, "Color: 0x" + Integer.toHexString(colorFormat));
    if (!isSupportedColorFormat(colorFormat)) {
      stopOnOutputThread(new IllegalStateException("Unsupported color format: " + colorFormat));
      return;
    }
  }

  // Save stride and sliceHeight under the dimension lock.
  synchronized (dimensionLock) {
    if (format.containsKey(MEDIA_FORMAT_KEY_STRIDE)) {
      stride = format.getInteger(MEDIA_FORMAT_KEY_STRIDE);
    }
    if (format.containsKey(MEDIA_FORMAT_KEY_SLICE_HEIGHT)) {
      sliceHeight = format.getInteger(MEDIA_FORMAT_KEY_SLICE_HEIGHT);
    }
    Logging.d(TAG, "Frame stride and slice height: " + stride + " x " + sliceHeight);
    stride = Math.max(width, stride);
    sliceHeight = Math.max(height, sliceHeight);
  }
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:53,代碼來源:HardwareVideoDecoder.java

示例6: fromMedia

import android.media.MediaFormat; //導入方法依賴的package包/類
public static MediaDescription fromMedia(MediaFormat m, final int payloadType, String control) {
    MediaDescription md = null;
    String media = null;
    Integer port = 0; // This means there is no port preference
    Integer numberOfPorts = null; // This means there is no port preference
    String proto = "RTP/AVP";
    List<Integer> payloadTypes = Collections.singletonList(payloadType);

    // MIME type
    String mimeType = null;
    if (m.containsKey(MediaFormat.KEY_MIME)) {
        mimeType = m.getString(MediaFormat.KEY_MIME);
    }

    // Sample rate
    Integer rate = null;
    if (m.containsKey(MediaFormat.KEY_SAMPLE_RATE)) {
        rate = m.getInteger(MediaFormat.KEY_SAMPLE_RATE);
    }

    // Channel count
    Integer channelCount = 1; // Default to mono
    if (m.containsKey(MediaFormat.KEY_CHANNEL_COUNT)) {
        channelCount = m.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
    }

    if (mimeType != null) {
        String[] mediaTypeArray = mimeType.split("/");
        String mimeSubType = null;
        if (mediaTypeArray.length == 2) {
            media = mediaTypeArray[0];
            mimeSubType = mediaTypeArray[1];
        }

        // Create MediaDescription and Rtpmap from parsed values
        md = new MediaDescription(media, port, numberOfPorts, proto, payloadTypes);
        Rtpmap map = new Rtpmap(payloadType, mimeSubType, rate, channelCount);

        md.setAttributeValue("rtpmap", map.toString());
        md.setAttributeValue("control", control);
    }

    return md;
}
 
開發者ID:devinbrown7,項目名稱:streaminglib,代碼行數:45,代碼來源:MediaDescription.java

示例7: dequeueOutputBuffer

import android.media.MediaFormat; //導入方法依賴的package包/類
private DecodedOutputBuffer dequeueOutputBuffer(int dequeueTimeoutMs) {
  checkOnMediaCodecThread();
  if (decodeStartTimeMs.isEmpty()) {
    return null;
  }
  // Drain the decoder until receiving a decoded buffer or hitting
  // MediaCodec.INFO_TRY_AGAIN_LATER.
  final MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
  while (true) {
    final int result =
        mediaCodec.dequeueOutputBuffer(info, TimeUnit.MILLISECONDS.toMicros(dequeueTimeoutMs));
    switch (result) {
      case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED:
        outputBuffers = mediaCodec.getOutputBuffers();
        Logging.d(TAG, "Decoder output buffers changed: " + outputBuffers.length);
        if (hasDecodedFirstFrame) {
          throw new RuntimeException("Unexpected output buffer change event.");
        }
        break;
      case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED:
        MediaFormat format = mediaCodec.getOutputFormat();
        Logging.d(TAG, "Decoder format changed: " + format.toString());
        int new_width = format.getInteger(MediaFormat.KEY_WIDTH);
        int new_height = format.getInteger(MediaFormat.KEY_HEIGHT);
        if (hasDecodedFirstFrame && (new_width != width || new_height != height)) {
          throw new RuntimeException("Unexpected size change. Configured " + width + "*" + height
              + ". New " + new_width + "*" + new_height);
        }
        width = format.getInteger(MediaFormat.KEY_WIDTH);
        height = format.getInteger(MediaFormat.KEY_HEIGHT);

        if (!useSurface && format.containsKey(MediaFormat.KEY_COLOR_FORMAT)) {
          colorFormat = format.getInteger(MediaFormat.KEY_COLOR_FORMAT);
          Logging.d(TAG, "Color: 0x" + Integer.toHexString(colorFormat));
          if (!supportedColorList.contains(colorFormat)) {
            throw new IllegalStateException("Non supported color format: " + colorFormat);
          }
        }
        if (format.containsKey("stride")) {
          stride = format.getInteger("stride");
        }
        if (format.containsKey("slice-height")) {
          sliceHeight = format.getInteger("slice-height");
        }
        Logging.d(TAG, "Frame stride and slice height: " + stride + " x " + sliceHeight);
        stride = Math.max(width, stride);
        sliceHeight = Math.max(height, sliceHeight);
        break;
      case MediaCodec.INFO_TRY_AGAIN_LATER:
        return null;
      default:
        hasDecodedFirstFrame = true;
        TimeStamps timeStamps = decodeStartTimeMs.remove();
        long decodeTimeMs = SystemClock.elapsedRealtime() - timeStamps.decodeStartTimeMs;
        if (decodeTimeMs > MAX_DECODE_TIME_MS) {
          Logging.e(TAG, "Very high decode time: " + decodeTimeMs + "ms"
                  + ". Q size: " + decodeStartTimeMs.size()
                  + ". Might be caused by resuming H264 decoding after a pause.");
          decodeTimeMs = MAX_DECODE_TIME_MS;
        }
        return new DecodedOutputBuffer(result, info.offset, info.size,
            TimeUnit.MICROSECONDS.toMillis(info.presentationTimeUs), timeStamps.timeStampMs,
            timeStamps.ntpTimeStampMs, decodeTimeMs, SystemClock.elapsedRealtime());
    }
  }
}
 
開發者ID:lgyjg,項目名稱:AndroidRTC,代碼行數:67,代碼來源:MediaCodecVideoDecoder.java


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