android.media.UnsupportedSchemeException#com.google.android.exoplayer.drm.DrmSessionManager源码实例Demo

下面列出了android.media.UnsupportedSchemeException#com.google.android.exoplayer.drm.DrmSessionManager 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Exoplayer_VLC   文件: MediaCodecTrackRenderer.java
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted media. May be null if support for encrypted
 *     media is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 */
public MediaCodecTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys, Handler eventHandler, EventListener eventListener) {
  Assertions.checkState(Util.SDK_INT >= 16);
  this.source = source;
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  this.eventHandler = eventHandler;
  this.eventListener = eventListener;
  codecCounters = new CodecCounters();
  sampleHolder = new SampleHolder(SampleHolder.BUFFER_REPLACEMENT_MODE_DISABLED);
  formatHolder = new MediaFormatHolder();
  decodeOnlyPresentationTimestamps = new ArrayList<Long>();
  outputBufferInfo = new MediaCodec.BufferInfo();

}
 
源代码2 项目: Exoplayer_VLC   文件: MediaCodecTrackRenderer.java
private boolean shouldWaitForKeys(boolean sampleEncrypted) throws ExoPlaybackException {
  if (!openedDrmSession) {
    return false;
  }
  int drmManagerState = drmSessionManager.getState();
  if (drmManagerState == DrmSessionManager.STATE_ERROR) {
    throw new ExoPlaybackException(drmSessionManager.getError());
  }
  if (drmManagerState != DrmSessionManager.STATE_OPENED_WITH_KEYS &&
      (sampleEncrypted || !playClearSamplesWithoutKeys)) {
    return true;
  }
  return false;
}
 
源代码3 项目: Mobilyzer   文件: DashVodRendererBuilder.java
public static Pair<DrmSessionManager, Boolean> getDrmSessionManagerData(DemoPlayer player,
    MediaDrmCallback drmCallback) throws UnsupportedSchemeException {
  StreamingDrmSessionManager streamingDrmSessionManager = new StreamingDrmSessionManager(
      DemoUtil.WIDEVINE_UUID, player.getPlaybackLooper(), drmCallback, player.getMainHandler(),
      player);
  return Pair.create((DrmSessionManager) streamingDrmSessionManager,
      getWidevineSecurityLevel(streamingDrmSessionManager) == SECURITY_LEVEL_1);
}
 
源代码4 项目: ShareBox   文件: SmoothStreamingRendererBuilder.java
@Override
public void onSingleManifest(SmoothStreamingManifest manifest) {
  if (canceled) {
    return;
  }

  Handler mainHandler = player.getMainHandler();
  LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);

  // Check drm support if necessary.
  DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
  if (manifest.protectionElement != null) {
    if (Util.SDK_INT < 18) {
      player.onRenderersError(
          new UnsupportedDrmException(UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME));
      return;
    }
    try {
      drmSessionManager = StreamingDrmSessionManager.newFrameworkInstance(
          manifest.protectionElement.uuid, player.getPlaybackLooper(), drmCallback, null,
          player.getMainHandler(), player);
    } catch (UnsupportedDrmException e) {
      player.onRenderersError(e);
      return;
    }
  }

  // Build the video renderer.
  DataSource videoDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource videoChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
      DefaultSmoothStreamingTrackSelector.newVideoInstance(context, true, false),
      videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS);
  ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
      VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_VIDEO);
  TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, videoSampleSource,
      MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
      drmSessionManager, true, mainHandler, player, 50);

  // Build the audio renderer.
  DataSource audioDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource audioChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
      DefaultSmoothStreamingTrackSelector.newAudioInstance(),
      audioDataSource, null, LIVE_EDGE_LATENCY_MS);
  ChunkSampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
      AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_AUDIO);
  TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource,
      MediaCodecSelector.DEFAULT, drmSessionManager, true, mainHandler, player,
      AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);

  // Build the text renderer.
  DataSource textDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource textChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
      DefaultSmoothStreamingTrackSelector.newTextInstance(),
      textDataSource, null, LIVE_EDGE_LATENCY_MS);
  ChunkSampleSource textSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
      TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_TEXT);
  TrackRenderer textRenderer = new TextTrackRenderer(textSampleSource, player,
      mainHandler.getLooper());

  // Invoke the callback.
  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
  player.onRenderers(renderers, bandwidthMeter);
}
 
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param videoScalingMode The scaling mode to pass to
 *     {@link MediaCodec#setVideoScalingMode(int)}.
 * @param allowedJoiningTimeMs The maximum duration in milliseconds for which this video renderer
 *     can attempt to seamlessly join an ongoing playback.
 * @param frameReleaseTimeHelper An optional helper to make fine-grained adjustments to frame
 *     release times. May be null.
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param maxDroppedFrameCountToNotify The maximum number of frames that can be dropped between
 *     invocations of {@link EventListener#onDroppedFrames(int, long)}.
 */
public MediaCodecVideoTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys, int videoScalingMode, long allowedJoiningTimeMs,
    FrameReleaseTimeHelper frameReleaseTimeHelper, Handler eventHandler,
    EventListener eventListener, int maxDroppedFrameCountToNotify) {
  super(source, drmSessionManager, playClearSamplesWithoutKeys, eventHandler, eventListener);
  this.videoScalingMode = videoScalingMode;
  this.allowedJoiningTimeUs = allowedJoiningTimeMs * 1000;
  this.frameReleaseTimeHelper = frameReleaseTimeHelper;
  this.eventListener = eventListener;
  this.maxDroppedFrameCountToNotify = maxDroppedFrameCountToNotify;
  joiningDeadlineUs = -1;
  currentWidth = -1;
  currentHeight = -1;
  currentPixelWidthHeightRatio = -1;
  lastReportedWidth = -1;
  lastReportedHeight = -1;
  lastReportedPixelWidthHeightRatio = -1;

}
 
@Override
public void onSingleManifest(SmoothStreamingManifest manifest) {
    if (canceled) {
        return;
    }

    Handler mainHandler = player.getMainHandler();
    LoadControl loadControl =
            new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);

    // Check drm support if necessary.
    DrmSessionManager drmSessionManager = null;
    if (manifest.protectionElement != null) {
        if (Util.SDK_INT < 18) {
            player.onRenderersError(new UnsupportedDrmException(
                    UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME));
            return;
        }
        try {
            drmSessionManager =  StreamingDrmSessionManager.newFrameworkInstance(
                    manifest.protectionElement.uuid, player.getPlaybackLooper(),
                    drmCallback, null, player.getMainHandler(), player);
        } catch (UnsupportedDrmException e) {
            player.onRenderersError(e);
            return;
        }
    }

    // Build the video renderer.
    DataSource videoDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource videoChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
            DefaultSmoothStreamingTrackSelector.newVideoInstance(context, true, false),
            videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS);
    ChunkSampleSource videoSampleSource =
            new ChunkSampleSource(videoChunkSource, loadControl,
                    VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
                    DemoPlayer.TYPE_VIDEO);
    TrackRenderer videoRenderer =
            new MediaCodecVideoTrackRenderer(context, videoSampleSource,
                    MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT,
                    5000, drmSessionManager, true, mainHandler, player, 50);

    // Build the audio renderer.
    DataSource audioDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource audioChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
            DefaultSmoothStreamingTrackSelector.newAudioInstance(),
            audioDataSource, null, LIVE_EDGE_LATENCY_MS);
    ChunkSampleSource audioSampleSource =
            new ChunkSampleSource(audioChunkSource, loadControl,
                    AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
                    DemoPlayer.TYPE_AUDIO);
    TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource,
            MediaCodecSelector.DEFAULT, drmSessionManager, true, mainHandler, player,
            AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);

    // Build the text renderer.
    DataSource textDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource textChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
            DefaultSmoothStreamingTrackSelector.newTextInstance(),
            textDataSource, null, LIVE_EDGE_LATENCY_MS);
    ChunkSampleSource textSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
            TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
            DemoPlayer.TYPE_TEXT);
    TrackRenderer textRenderer = new TextTrackRenderer(textSampleSource, player,
            mainHandler.getLooper());

    // Invoke the callback.
    TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
    renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
    renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
    renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
    player.onRenderers(renderers, bandwidthMeter);
}
 
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 */
public MediaCodecAudioTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys, Handler eventHandler, EventListener eventListener) {
  super(source, drmSessionManager, playClearSamplesWithoutKeys, eventHandler, eventListener);
  this.eventListener = eventListener;
  this.audioSessionId = AudioTrack.SESSION_ID_NOT_SET;
  this.audioTrack = new AudioTrack();
}
 
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param videoScalingMode The scaling mode to pass to
 *     {@link MediaCodec#setVideoScalingMode(int)}.
 */
public MediaCodecVideoTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys, int videoScalingMode) {
  this(source, drmSessionManager, playClearSamplesWithoutKeys, videoScalingMode, 0);
}
 
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param videoScalingMode The scaling mode to pass to
 *     {@link MediaCodec#setVideoScalingMode(int)}.
 * @param allowedJoiningTimeMs The maximum duration in milliseconds for which this video renderer
 *     can attempt to seamlessly join an ongoing playback.
 */
public MediaCodecVideoTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys, int videoScalingMode, long allowedJoiningTimeMs) {
  this(source, drmSessionManager, playClearSamplesWithoutKeys, videoScalingMode,
      allowedJoiningTimeMs, null, null, null, -1);
}
 
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 */
public MediaCodecAudioTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys) {
  this(source, drmSessionManager, playClearSamplesWithoutKeys, null, null);
}