com.google.android.exoplayer2.drm.DefaultDrmSessionManager Java Examples

The following examples show how to use com.google.android.exoplayer2.drm.DefaultDrmSessionManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MediaPlayerFragment.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
private DrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManager(UUID uuid,
																	   String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException {
	if (Util.SDK_INT < 18) {
		return null;
	}
	HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(licenseUrl,
																buildHttpDataSourceFactory(false));
	if (keyRequestPropertiesArray != null) {
		for (int i = 0; i < keyRequestPropertiesArray.length - 1; i += 2) {
			drmCallback.setKeyRequestProperty(keyRequestPropertiesArray[i],
											  keyRequestPropertiesArray[i + 1]);
		}
	}
	return new DefaultDrmSessionManager<FrameworkMediaCrypto>(uuid,
										  FrameworkMediaDrm.newInstance(uuid), drmCallback, null, mainHandler, eventLogger);
}
 
Example #2
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 6 votes vote down vote up
@Override
protected final DefaultDrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManager(
    final String userAgent) {
  DefaultDrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
  if (parameters.isWidevineEncrypted) {
    try {
      MediaDrmCallback drmCallback = new HttpMediaDrmCallback(parameters.widevineLicenseUrl,
          new DefaultHttpDataSourceFactory(userAgent));
      drmSessionManager = DefaultDrmSessionManager.newWidevineInstance(drmCallback, null,
          null, null);
      if (!parameters.useL1Widevine) {
        drmSessionManager.setPropertyString(SECURITY_LEVEL_PROPERTY, WIDEVINE_SECURITY_LEVEL_3);
      }
      if (offlineLicenseKeySetId != null) {
        drmSessionManager.setMode(DefaultDrmSessionManager.MODE_PLAYBACK,
            offlineLicenseKeySetId);
      }
    } catch (UnsupportedDrmException e) {
      throw new IllegalStateException(e);
    }
  }
  return drmSessionManager;
}
 
Example #3
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
/**
 * Generates the {@link DrmSessionManager} to use with the {@link RendererProvider}. This will
 * return null on API's &lt; {@value Build.VERSION_CODES#JELLY_BEAN_MR2}
 *
 * @return The {@link DrmSessionManager} to use or <code>null</code>
 */
@Nullable
protected DrmSessionManager<FrameworkMediaCrypto> generateDrmSessionManager() {
    // DRM is only supported on API 18 + in the ExoPlayer
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return null;
    }

    // Widevine will capture the majority of use cases however playready is supported on all AndroidTV devices
    UUID uuid = C.WIDEVINE_UUID;

    try {
        DefaultDrmSessionManager<FrameworkMediaCrypto> sessionManager = new DefaultDrmSessionManager<>(uuid, FrameworkMediaDrm.newInstance(uuid), new DelegatedMediaDrmCallback(), null);
        sessionManager.addListener(mainHandler, capabilitiesListener);

        return sessionManager;
    } catch (Exception e) {
        Log.d(TAG, "Unable to create a DrmSessionManager due to an exception", e);
        return null;
    }
}
 
Example #4
Source File: PlayerActivity.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
private DrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManager(UUID uuid,
                                                                       String licenseUrl, Map<String, String> keyRequestProperties) throws UnsupportedDrmException {
    if (Util.SDK_INT < 18) {
        return null;
    }
    HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(licenseUrl,
            buildHttpDataSourceFactory(false), keyRequestProperties);
    return new DefaultDrmSessionManager<>(uuid,
            FrameworkMediaDrm.newInstance(uuid), drmCallback, null, mainHandler, eventLogger);
}
 
Example #5
Source File: StreamingDrmSessionCreator.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Override
public DrmSessionManager<FrameworkMediaCrypto> create(DefaultDrmSessionEventListener eventListener) {
    FrameworkMediaDrm frameworkMediaDrm = frameworkMediaDrmCreator.create(WIDEVINE_MODULAR_UUID);

    DefaultDrmSessionManager<FrameworkMediaCrypto> defaultDrmSessionManager = new DefaultDrmSessionManager<>(
            WIDEVINE_MODULAR_UUID,
            frameworkMediaDrm,
            mediaDrmCallback,
            NO_OPTIONAL_PARAMETERS
    );
    defaultDrmSessionManager.removeListener(eventListener);
    defaultDrmSessionManager.addListener(handler, eventListener);

    return defaultDrmSessionManager;
}
 
Example #6
Source File: RendererErrorMapper.java    From no-player with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"PMD.StdCyclomaticComplexity", "PMD.CyclomaticComplexity", "PMD.ModifiedCyclomaticComplexity", "PMD.NPathComplexity"})
static NoPlayer.PlayerError map(Exception rendererException, String message) {
    if (rendererException instanceof AudioSink.ConfigurationException) {
        return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.AUDIO_SINK_CONFIGURATION_ERROR, message);
    }

    if (rendererException instanceof AudioSink.InitializationException) {
        return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.AUDIO_SINK_INITIALISATION_ERROR, message);
    }

    if (rendererException instanceof AudioSink.WriteException) {
        return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.AUDIO_SINK_WRITE_ERROR, message);
    }

    if (rendererException instanceof AudioProcessor.UnhandledFormatException) {
        return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.AUDIO_UNHANDLED_FORMAT_ERROR, message);
    }

    if (rendererException instanceof AudioDecoderException) {
        return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.AUDIO_DECODER_ERROR, message);
    }

    if (rendererException instanceof MediaCodecRenderer.DecoderInitializationException) {
        MediaCodecRenderer.DecoderInitializationException decoderInitializationException =
                (MediaCodecRenderer.DecoderInitializationException) rendererException;
        String fullMessage = "decoder-name:" + decoderInitializationException.decoderName + ", "
                + "mimetype:" + decoderInitializationException.mimeType + ", "
                + "secureCodeRequired:" + decoderInitializationException.secureDecoderRequired + ", "
                + "diagnosticInfo:" + decoderInitializationException.diagnosticInfo + ", "
                + "exceptionMessage:" + message;
        return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.INITIALISATION_ERROR, fullMessage);
    }

    if (rendererException instanceof MediaCodecUtil.DecoderQueryException) {
        return new NoPlayerError(PlayerErrorType.DEVICE_MEDIA_CAPABILITIES, DetailErrorType.UNKNOWN, message);
    }

    if (rendererException instanceof SubtitleDecoderException) {
        return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.DECODING_SUBTITLE_ERROR, message);
    }

    if (rendererException instanceof UnsupportedDrmException) {
        return mapUnsupportedDrmException((UnsupportedDrmException) rendererException, message);
    }

    if (rendererException instanceof DefaultDrmSessionManager.MissingSchemeDataException) {
        return new NoPlayerError(PlayerErrorType.DRM, DetailErrorType.CANNOT_ACQUIRE_DRM_SESSION_MISSING_SCHEME_FOR_REQUIRED_UUID_ERROR, message);
    }

    if (rendererException instanceof DrmSession.DrmSessionException) {
        return new NoPlayerError(PlayerErrorType.DRM, DetailErrorType.DRM_SESSION_ERROR, message);
    }

    if (rendererException instanceof KeysExpiredException) {
        return new NoPlayerError(PlayerErrorType.DRM, DetailErrorType.DRM_KEYS_EXPIRED_ERROR, message);
    }

    if (rendererException instanceof DecryptionException) {
        return new NoPlayerError(PlayerErrorType.CONTENT_DECRYPTION, DetailErrorType.FAIL_DECRYPT_DATA_DUE_NON_PLATFORM_COMPONENT_ERROR, message);
    }

    if (rendererException instanceof MediaCodec.CryptoException) {
        return mapCryptoException((MediaCodec.CryptoException) rendererException, message);
    }

    if (rendererException instanceof IllegalStateException) {
        return new NoPlayerError(PlayerErrorType.DRM, DetailErrorType.MEDIA_REQUIRES_DRM_SESSION_MANAGER_ERROR, message);
    }

    return new NoPlayerError(PlayerErrorType.UNKNOWN, DetailErrorType.UNKNOWN, message);
}
 
Example #7
Source File: SimpleExoPlayer.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollector The {@link AnalyticsCollector} that will collect and forward all
 *     player events.
 * @param clock The {@link Clock} that will be used by the instance. Should always be {@link
 *     Clock#DEFAULT}, unless the player is being used from a test.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 * @deprecated Use {@link #SimpleExoPlayer(Context, RenderersFactory, TrackSelector, LoadControl,
 *     BandwidthMeter, AnalyticsCollector, Clock, Looper)} instead, and pass the {@link
 *     DrmSessionManager} to the {@link MediaSource} factories.
 */
@Deprecated
protected SimpleExoPlayer(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector analyticsCollector,
    Clock clock,
    Looper looper) {
  this.bandwidthMeter = bandwidthMeter;
  this.analyticsCollector = analyticsCollector;
  componentListener = new ComponentListener();
  videoListeners = new CopyOnWriteArraySet<>();
  audioListeners = new CopyOnWriteArraySet<>();
  textOutputs = new CopyOnWriteArraySet<>();
  metadataOutputs = new CopyOnWriteArraySet<>();
  videoDebugListeners = new CopyOnWriteArraySet<>();
  audioDebugListeners = new CopyOnWriteArraySet<>();
  eventHandler = new Handler(looper);
  renderers =
      renderersFactory.createRenderers(
          eventHandler,
          componentListener,
          componentListener,
          componentListener,
          componentListener,
          drmSessionManager);

  // Set initial values.
  audioVolume = 1;
  audioSessionId = C.AUDIO_SESSION_ID_UNSET;
  audioAttributes = AudioAttributes.DEFAULT;
  videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
  currentCues = Collections.emptyList();

  // Build the player and associated objects.
  player =
      new ExoPlayerImpl(renderers, trackSelector, loadControl, bandwidthMeter, clock, looper);
  analyticsCollector.setPlayer(player);
  addListener(analyticsCollector);
  addListener(componentListener);
  videoDebugListeners.add(analyticsCollector);
  videoListeners.add(analyticsCollector);
  audioDebugListeners.add(analyticsCollector);
  audioListeners.add(analyticsCollector);
  addMetadataOutput(analyticsCollector);
  bandwidthMeter.addEventListener(eventHandler, analyticsCollector);
  if (drmSessionManager instanceof DefaultDrmSessionManager) {
    ((DefaultDrmSessionManager) drmSessionManager).addListener(eventHandler, analyticsCollector);
  }
  audioBecomingNoisyManager =
      new AudioBecomingNoisyManager(context, eventHandler, componentListener);
  audioFocusManager = new AudioFocusManager(context, eventHandler, componentListener);
  wakeLockManager = new WakeLockManager(context);
}
 
Example #8
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param clock The {@link Clock} that will be used by the instance. Should always be {@link
 *     Clock#DEFAULT}, unless the player is being used from a test.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Clock clock,
    Looper looper) {
  this.bandwidthMeter = bandwidthMeter;
  componentListener = new ComponentListener();
  videoListeners = new CopyOnWriteArraySet<>();
  audioListeners = new CopyOnWriteArraySet<>();
  textOutputs = new CopyOnWriteArraySet<>();
  metadataOutputs = new CopyOnWriteArraySet<>();
  videoDebugListeners = new CopyOnWriteArraySet<>();
  audioDebugListeners = new CopyOnWriteArraySet<>();
  eventHandler = new Handler(looper);
  renderers =
      renderersFactory.createRenderers(
          eventHandler,
          componentListener,
          componentListener,
          componentListener,
          componentListener,
          drmSessionManager);

  // Set initial values.
  audioVolume = 1;
  audioSessionId = C.AUDIO_SESSION_ID_UNSET;
  audioAttributes = AudioAttributes.DEFAULT;
  videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
  currentCues = Collections.emptyList();

  // Build the player and associated objects.
  player =
      createExoPlayerImpl(renderers, trackSelector, loadControl, bandwidthMeter, clock, looper);
  analyticsCollector = analyticsCollectorFactory.createAnalyticsCollector(player, clock);
  addListener(analyticsCollector);
  videoDebugListeners.add(analyticsCollector);
  videoListeners.add(analyticsCollector);
  audioDebugListeners.add(analyticsCollector);
  audioListeners.add(analyticsCollector);
  addMetadataOutput(analyticsCollector);
  bandwidthMeter.addEventListener(eventHandler, analyticsCollector);
  if (drmSessionManager instanceof DefaultDrmSessionManager) {
    ((DefaultDrmSessionManager) drmSessionManager).addListener(eventHandler, analyticsCollector);
  }
}
 
Example #9
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param clock The {@link Clock} that will be used by the instance. Should always be {@link
 *     Clock#DEFAULT}, unless the player is being used from a test.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Clock clock,
    Looper looper) {
  this.bandwidthMeter = bandwidthMeter;
  componentListener = new ComponentListener();
  videoListeners = new CopyOnWriteArraySet<>();
  audioListeners = new CopyOnWriteArraySet<>();
  textOutputs = new CopyOnWriteArraySet<>();
  metadataOutputs = new CopyOnWriteArraySet<>();
  videoDebugListeners = new CopyOnWriteArraySet<>();
  audioDebugListeners = new CopyOnWriteArraySet<>();
  eventHandler = new Handler(looper);
  renderers =
      renderersFactory.createRenderers(
          eventHandler,
          componentListener,
          componentListener,
          componentListener,
          componentListener,
          drmSessionManager);

  // Set initial values.
  audioVolume = 1;
  audioSessionId = C.AUDIO_SESSION_ID_UNSET;
  audioAttributes = AudioAttributes.DEFAULT;
  videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
  currentCues = Collections.emptyList();

  // Build the player and associated objects.
  player =
      createExoPlayerImpl(renderers, trackSelector, loadControl, bandwidthMeter, clock, looper);
  analyticsCollector = analyticsCollectorFactory.createAnalyticsCollector(player, clock);
  addListener(analyticsCollector);
  videoDebugListeners.add(analyticsCollector);
  videoListeners.add(analyticsCollector);
  audioDebugListeners.add(analyticsCollector);
  audioListeners.add(analyticsCollector);
  addMetadataOutput(analyticsCollector);
  bandwidthMeter.addEventListener(eventHandler, analyticsCollector);
  if (drmSessionManager instanceof DefaultDrmSessionManager) {
    ((DefaultDrmSessionManager) drmSessionManager).addListener(eventHandler, analyticsCollector);
  }
}
 
Example #10
Source File: PlayerActivity.java    From ExoPlayer-Offline with Apache License 2.0 4 votes vote down vote up
private DrmSessionManager<FrameworkMediaCrypto> buildOfflineDrmSessionManager(UUID uuid,
                                                                              String licenseUrl, Map<String, String> keyRequestProperties) throws UnsupportedDrmException, IOException, DrmSession.DrmSessionException, InterruptedException {
    if (Util.SDK_INT < 18) {
        return null;
    }

    customDrmCallback = new CustomDrmCallback(
            DemoApplication.getAppInstance().buildHttpDataSourceFactory(new DefaultBandwidthMeter()),
            licenseUrl
    );

    DefaultDrmSessionManager<FrameworkMediaCrypto> drmSessionManager = new DefaultDrmSessionManager<>(uuid,
            FrameworkMediaDrm.newInstance(uuid), customDrmCallback, null, mainHandler, eventLogger);

    String offlineAssetKeyIdStr = DemoApplication.getAppInstance().
            getSharedPreferences().getString(DemoApplication.KEY_OFFLINE_OFFSET_ID,DemoApplication.EMPTY);
    byte[] offlineAssetKeyId = Base64.decode(offlineAssetKeyIdStr, Base64.DEFAULT);
    this.offlineLicenseHelper = OfflineLicenseHelper.newWidevineInstance(customDrmCallback, null);
    Pair<Long, Long> remainingSecPair = offlineLicenseHelper.getLicenseDurationRemainingSec(offlineAssetKeyId);
    Log.e(TAG," License remaining Play time : "+remainingSecPair.first+", Purchase time : "+remainingSecPair.second);
    if(DemoApplication.EMPTY.equals(offlineAssetKeyIdStr) || ( remainingSecPair.first == 0 || remainingSecPair.second == 0)) {
        String path = getIntent().getStringExtra(EXTRA_OFFLINE_URI);
        File file = getUriForManifest(path);
        Uri uri = Uri.fromFile(file);
        InputStream is = new FileInputStream(file);
        Log.e(TAG, "will start download now");
        offlineAssetKeyId = offlineLicenseHelper.download(
                DemoApplication.getAppInstance().buildHttpDataSourceFactory(new DefaultBandwidthMeter()).createDataSource(),
                new DashManifestParser().parse(uri, is));
        Pair<Long, Long> p = offlineLicenseHelper.getLicenseDurationRemainingSec(offlineAssetKeyId);
        Log.e(TAG, "download done : " + p.toString());

        SharedPreferences sharedPreferences = DemoApplication.getAppInstance().getSharedPreferences();
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(DemoApplication.KEY_OFFLINE_OFFSET_ID,
                Base64.encodeToString(offlineAssetKeyId, Base64.DEFAULT));
        editor.commit();
    }


    drmSessionManager.setMode(DefaultDrmSessionManager.MODE_QUERY,offlineAssetKeyId);
    return drmSessionManager;
}
 
Example #11
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 4 votes vote down vote up
protected void setupDamSessionManagerAnalytics(DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
    if (drmSessionManager instanceof DefaultDrmSessionManager) {
        ((DefaultDrmSessionManager) drmSessionManager).addListener(mainHandler, analyticsCollector);
    }
}
 
Example #12
Source File: SimpleExoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param clock The {@link Clock} that will be used by the instance. Should always be {@link
 *     Clock#DEFAULT}, unless the player is being used from a test.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Clock clock,
    Looper looper) {
  this.bandwidthMeter = bandwidthMeter;
  componentListener = new ComponentListener();
  videoListeners = new CopyOnWriteArraySet<>();
  audioListeners = new CopyOnWriteArraySet<>();
  textOutputs = new CopyOnWriteArraySet<>();
  metadataOutputs = new CopyOnWriteArraySet<>();
  videoDebugListeners = new CopyOnWriteArraySet<>();
  audioDebugListeners = new CopyOnWriteArraySet<>();
  eventHandler = new Handler(looper);
  renderers =
      renderersFactory.createRenderers(
          eventHandler,
          componentListener,
          componentListener,
          componentListener,
          componentListener,
          drmSessionManager);

  // Set initial values.
  audioVolume = 1;
  audioSessionId = C.AUDIO_SESSION_ID_UNSET;
  audioAttributes = AudioAttributes.DEFAULT;
  videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
  currentCues = Collections.emptyList();

  // Build the player and associated objects.
  player =
      new ExoPlayerImpl(renderers, trackSelector, loadControl, bandwidthMeter, clock, looper);
  analyticsCollector = analyticsCollectorFactory.createAnalyticsCollector(player, clock);
  addListener(analyticsCollector);
  addListener(componentListener);
  videoDebugListeners.add(analyticsCollector);
  videoListeners.add(analyticsCollector);
  audioDebugListeners.add(analyticsCollector);
  audioListeners.add(analyticsCollector);
  addMetadataOutput(analyticsCollector);
  bandwidthMeter.addEventListener(eventHandler, analyticsCollector);
  if (drmSessionManager instanceof DefaultDrmSessionManager) {
    ((DefaultDrmSessionManager) drmSessionManager).addListener(eventHandler, analyticsCollector);
  }
  audioFocusManager = new AudioFocusManager(context, componentListener);
}
 
Example #13
Source File: SimpleExoPlayer.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param clock The {@link Clock} that will be used by the instance. Should always be {@link
 *     Clock#DEFAULT}, unless the player is being used from a test.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Clock clock,
    Looper looper) {
  this.bandwidthMeter = bandwidthMeter;
  componentListener = new ComponentListener();
  videoListeners = new CopyOnWriteArraySet<>();
  audioListeners = new CopyOnWriteArraySet<>();
  textOutputs = new CopyOnWriteArraySet<>();
  metadataOutputs = new CopyOnWriteArraySet<>();
  videoDebugListeners = new CopyOnWriteArraySet<>();
  audioDebugListeners = new CopyOnWriteArraySet<>();
  eventHandler = new Handler(looper);
  renderers =
      renderersFactory.createRenderers(
          eventHandler,
          componentListener,
          componentListener,
          componentListener,
          componentListener,
          drmSessionManager);

  // Set initial values.
  audioVolume = 1;
  audioSessionId = C.AUDIO_SESSION_ID_UNSET;
  audioAttributes = AudioAttributes.DEFAULT;
  videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
  currentCues = Collections.emptyList();

  // Build the player and associated objects.
  player =
      new ExoPlayerImpl(renderers, trackSelector, loadControl, bandwidthMeter, clock, looper);
  analyticsCollector = analyticsCollectorFactory.createAnalyticsCollector(player, clock);
  addListener(analyticsCollector);
  addListener(componentListener);
  videoDebugListeners.add(analyticsCollector);
  videoListeners.add(analyticsCollector);
  audioDebugListeners.add(analyticsCollector);
  audioListeners.add(analyticsCollector);
  addMetadataOutput(analyticsCollector);
  bandwidthMeter.addEventListener(eventHandler, analyticsCollector);
  if (drmSessionManager instanceof DefaultDrmSessionManager) {
    ((DefaultDrmSessionManager) drmSessionManager).addListener(eventHandler, analyticsCollector);
  }
  audioFocusManager = new AudioFocusManager(context, componentListener);
}