当前位置: 首页>>代码示例>>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;未经允许,请勿转载。