Search in sources :

Example 1 with HttpMediaDrmCallback

use of com.google.android.exoplayer2.drm.HttpMediaDrmCallback in project ExoPlayer by google.

the class MainActivity method initializePlayer.

private void initializePlayer() {
    Intent intent = getIntent();
    String action = intent.getAction();
    Uri uri = ACTION_VIEW.equals(action) ? Assertions.checkNotNull(intent.getData()) : Uri.parse(DEFAULT_MEDIA_URI);
    DrmSessionManager drmSessionManager;
    if (Util.SDK_INT >= 18 && intent.hasExtra(DRM_SCHEME_EXTRA)) {
        String drmScheme = Assertions.checkNotNull(intent.getStringExtra(DRM_SCHEME_EXTRA));
        String drmLicenseUrl = Assertions.checkNotNull(intent.getStringExtra(DRM_LICENSE_URL_EXTRA));
        UUID drmSchemeUuid = Assertions.checkNotNull(Util.getDrmUuid(drmScheme));
        HttpDataSource.Factory licenseDataSourceFactory = new DefaultHttpDataSource.Factory();
        HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(drmLicenseUrl, licenseDataSourceFactory);
        drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(drmSchemeUuid, FrameworkMediaDrm.DEFAULT_PROVIDER).build(drmCallback);
    } else {
        drmSessionManager = DrmSessionManager.DRM_UNSUPPORTED;
    }
    DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(this);
    MediaSource mediaSource;
    @C.ContentType int type = Util.inferContentType(uri, intent.getStringExtra(EXTENSION_EXTRA));
    if (type == C.TYPE_DASH) {
        mediaSource = new DashMediaSource.Factory(dataSourceFactory).setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).createMediaSource(MediaItem.fromUri(uri));
    } else if (type == C.TYPE_OTHER) {
        mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).createMediaSource(MediaItem.fromUri(uri));
    } else {
        throw new IllegalStateException();
    }
    ExoPlayer player = new ExoPlayer.Builder(getApplicationContext()).build();
    player.setRepeatMode(Player.REPEAT_MODE_ALL);
    player.setMediaSource(mediaSource);
    player.prepare();
    player.play();
    VideoProcessingGLSurfaceView videoProcessingGLSurfaceView = Assertions.checkNotNull(this.videoProcessingGLSurfaceView);
    videoProcessingGLSurfaceView.setPlayer(player);
    Assertions.checkNotNull(playerView).setPlayer(player);
    player.addAnalyticsListener(new EventLogger(/* trackSelector= */
    null));
    this.player = player;
}
Also used : Context(android.content.Context) Util(com.google.android.exoplayer2.util.Util) Bundle(android.os.Bundle) FrameworkMediaDrm(com.google.android.exoplayer2.drm.FrameworkMediaDrm) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) Intent(android.content.Intent) Player(com.google.android.exoplayer2.Player) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) Toast(android.widget.Toast) EventLogger(com.google.android.exoplayer2.util.EventLogger) MediaSource(com.google.android.exoplayer2.source.MediaSource) C(com.google.android.exoplayer2.C) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) MediaItem(com.google.android.exoplayer2.MediaItem) HttpMediaDrmCallback(com.google.android.exoplayer2.drm.HttpMediaDrmCallback) StyledPlayerView(com.google.android.exoplayer2.ui.StyledPlayerView) UUID(java.util.UUID) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) GlUtil(com.google.android.exoplayer2.util.GlUtil) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) Nullable(androidx.annotation.Nullable) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) Activity(android.app.Activity) Assertions(com.google.android.exoplayer2.util.Assertions) EventLogger(com.google.android.exoplayer2.util.EventLogger) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) Intent(android.content.Intent) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) Uri(android.net.Uri) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) HttpMediaDrmCallback(com.google.android.exoplayer2.drm.HttpMediaDrmCallback) UUID(java.util.UUID)

Example 2 with HttpMediaDrmCallback

use of com.google.android.exoplayer2.drm.HttpMediaDrmCallback in project ExoPlayer by google.

the class MainActivity method initializePlayer.

private void initializePlayer() {
    Intent intent = getIntent();
    String action = intent.getAction();
    Uri uri = ACTION_VIEW.equals(action) ? Assertions.checkNotNull(intent.getData()) : Uri.parse(DEFAULT_MEDIA_URI);
    DrmSessionManager drmSessionManager;
    if (intent.hasExtra(DRM_SCHEME_EXTRA)) {
        String drmScheme = Assertions.checkNotNull(intent.getStringExtra(DRM_SCHEME_EXTRA));
        String drmLicenseUrl = Assertions.checkNotNull(intent.getStringExtra(DRM_LICENSE_URL_EXTRA));
        UUID drmSchemeUuid = Assertions.checkNotNull(Util.getDrmUuid(drmScheme));
        HttpDataSource.Factory licenseDataSourceFactory = new DefaultHttpDataSource.Factory();
        HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(drmLicenseUrl, licenseDataSourceFactory);
        drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(drmSchemeUuid, FrameworkMediaDrm.DEFAULT_PROVIDER).build(drmCallback);
    } else {
        drmSessionManager = DrmSessionManager.DRM_UNSUPPORTED;
    }
    DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(this);
    MediaSource mediaSource;
    @C.ContentType int type = Util.inferContentType(uri, intent.getStringExtra(EXTENSION_EXTRA));
    if (type == C.TYPE_DASH) {
        mediaSource = new DashMediaSource.Factory(dataSourceFactory).setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).createMediaSource(MediaItem.fromUri(uri));
    } else if (type == C.TYPE_OTHER) {
        mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).createMediaSource(MediaItem.fromUri(uri));
    } else {
        throw new IllegalStateException();
    }
    ExoPlayer player = new ExoPlayer.Builder(getApplicationContext()).build();
    player.setMediaSource(mediaSource);
    player.prepare();
    player.play();
    player.setRepeatMode(Player.REPEAT_MODE_ALL);
    surfaceControl = new SurfaceControl.Builder().setName(SURFACE_CONTROL_NAME).setBufferSize(/* width= */
    0, /* height= */
    0).build();
    videoSurface = new Surface(surfaceControl);
    player.setVideoSurface(videoSurface);
    MainActivity.player = player;
}
Also used : Util(com.google.android.exoplayer2.util.Util) PlayerControlView(com.google.android.exoplayer2.ui.PlayerControlView) Bundle(android.os.Bundle) SurfaceView(android.view.SurfaceView) FrameworkMediaDrm(com.google.android.exoplayer2.drm.FrameworkMediaDrm) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) Uri(android.net.Uri) Intent(android.content.Intent) Player(com.google.android.exoplayer2.Player) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) View(android.view.View) Button(android.widget.Button) SurfaceHolder(android.view.SurfaceHolder) MediaSource(com.google.android.exoplayer2.source.MediaSource) GridLayout(android.widget.GridLayout) C(com.google.android.exoplayer2.C) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) MediaItem(com.google.android.exoplayer2.MediaItem) HttpMediaDrmCallback(com.google.android.exoplayer2.drm.HttpMediaDrmCallback) Surface(android.view.Surface) UUID(java.util.UUID) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) Nullable(androidx.annotation.Nullable) SurfaceControl(android.view.SurfaceControl) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) Activity(android.app.Activity) Assertions(com.google.android.exoplayer2.util.Assertions) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) Intent(android.content.Intent) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) Uri(android.net.Uri) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) Surface(android.view.Surface) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) HttpMediaDrmCallback(com.google.android.exoplayer2.drm.HttpMediaDrmCallback) UUID(java.util.UUID)

Aggregations

Activity (android.app.Activity)2 Intent (android.content.Intent)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 Nullable (androidx.annotation.Nullable)2 C (com.google.android.exoplayer2.C)2 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)2 MediaItem (com.google.android.exoplayer2.MediaItem)2 Player (com.google.android.exoplayer2.Player)2 DefaultDrmSessionManager (com.google.android.exoplayer2.drm.DefaultDrmSessionManager)2 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)2 FrameworkMediaDrm (com.google.android.exoplayer2.drm.FrameworkMediaDrm)2 HttpMediaDrmCallback (com.google.android.exoplayer2.drm.HttpMediaDrmCallback)2 MediaSource (com.google.android.exoplayer2.source.MediaSource)2 ProgressiveMediaSource (com.google.android.exoplayer2.source.ProgressiveMediaSource)2 DashMediaSource (com.google.android.exoplayer2.source.dash.DashMediaSource)2 DataSource (com.google.android.exoplayer2.upstream.DataSource)2 DefaultDataSource (com.google.android.exoplayer2.upstream.DefaultDataSource)2 DefaultHttpDataSource (com.google.android.exoplayer2.upstream.DefaultHttpDataSource)2 HttpDataSource (com.google.android.exoplayer2.upstream.HttpDataSource)2