Search in sources :

Example 1 with EventLogger

use of androidx.media3.exoplayer.util.EventLogger in project media by androidx.

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) Bundle(android.os.Bundle) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) Intent(android.content.Intent) GlUtil(androidx.media3.common.util.GlUtil) HttpDataSource(androidx.media3.datasource.HttpDataSource) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Toast(android.widget.Toast) Assertions(androidx.media3.common.util.Assertions) DefaultDataSource(androidx.media3.datasource.DefaultDataSource) MediaItem(androidx.media3.common.MediaItem) DashMediaSource(androidx.media3.exoplayer.dash.DashMediaSource) DefaultDrmSessionManager(androidx.media3.exoplayer.drm.DefaultDrmSessionManager) MediaSource(androidx.media3.exoplayer.source.MediaSource) Player(androidx.media3.common.Player) FrameworkMediaDrm(androidx.media3.exoplayer.drm.FrameworkMediaDrm) ProgressiveMediaSource(androidx.media3.exoplayer.source.ProgressiveMediaSource) UUID(java.util.UUID) Util(androidx.media3.common.util.Util) DefaultHttpDataSource(androidx.media3.datasource.DefaultHttpDataSource) HttpMediaDrmCallback(androidx.media3.exoplayer.drm.HttpMediaDrmCallback) DataSource(androidx.media3.datasource.DataSource) EventLogger(androidx.media3.exoplayer.util.EventLogger) C(androidx.media3.common.C) Nullable(androidx.annotation.Nullable) PlayerView(androidx.media3.ui.PlayerView) Activity(android.app.Activity) EventLogger(androidx.media3.exoplayer.util.EventLogger) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) DefaultDrmSessionManager(androidx.media3.exoplayer.drm.DefaultDrmSessionManager) DefaultDrmSessionManager(androidx.media3.exoplayer.drm.DefaultDrmSessionManager) DashMediaSource(androidx.media3.exoplayer.dash.DashMediaSource) Intent(android.content.Intent) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Uri(android.net.Uri) HttpDataSource(androidx.media3.datasource.HttpDataSource) DefaultDataSource(androidx.media3.datasource.DefaultDataSource) DefaultHttpDataSource(androidx.media3.datasource.DefaultHttpDataSource) DataSource(androidx.media3.datasource.DataSource) DashMediaSource(androidx.media3.exoplayer.dash.DashMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) ProgressiveMediaSource(androidx.media3.exoplayer.source.ProgressiveMediaSource) HttpDataSource(androidx.media3.datasource.HttpDataSource) DefaultHttpDataSource(androidx.media3.datasource.DefaultHttpDataSource) HttpMediaDrmCallback(androidx.media3.exoplayer.drm.HttpMediaDrmCallback) UUID(java.util.UUID)

Example 2 with EventLogger

use of androidx.media3.exoplayer.util.EventLogger in project media by androidx.

the class ExoHostedTest method onStart.

// HostedTest implementation
@Override
public final void onStart(HostActivity host, Surface surface, FrameLayout overlayFrameLayout) {
    this.surface = surface;
    // Build the player.
    trackSelector = buildTrackSelector(host);
    player = buildExoPlayer(host, surface, trackSelector);
    player.play();
    player.addAnalyticsListener(this);
    player.addAnalyticsListener(new EventLogger(trackSelector, tag));
    // Schedule any pending actions.
    actionHandler = Clock.DEFAULT.createHandler(Util.getCurrentOrMainLooper(), /* callback= */
    null);
    if (pendingSchedule != null) {
        pendingSchedule.start(player, trackSelector, surface, actionHandler, /* callback= */
        null);
        pendingSchedule = null;
    }
    DrmSessionManager drmSessionManager = buildDrmSessionManager();
    player.setMediaSource(buildSource(host, drmSessionManager, overlayFrameLayout));
    player.prepare();
}
Also used : EventLogger(androidx.media3.exoplayer.util.EventLogger) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager)

Example 3 with EventLogger

use of androidx.media3.exoplayer.util.EventLogger in project media by androidx.

the class PlayerActivity method initializePlayer.

/**
 * @return Whether initialization was successful.
 */
protected boolean initializePlayer() {
    if (player == null) {
        Intent intent = getIntent();
        mediaItems = createMediaItems(intent);
        if (mediaItems.isEmpty()) {
            return false;
        }
        boolean preferExtensionDecoders = intent.getBooleanExtra(IntentUtil.PREFER_EXTENSION_DECODERS_EXTRA, false);
        RenderersFactory renderersFactory = DemoUtil.buildRenderersFactory(/* context= */
        this, preferExtensionDecoders);
        trackSelector = new DefaultTrackSelector(/* context= */
        this);
        lastSeenTracksInfo = TracksInfo.EMPTY;
        player = new ExoPlayer.Builder(/* context= */
        this).setRenderersFactory(renderersFactory).setMediaSourceFactory(createMediaSourceFactory()).setTrackSelector(trackSelector).build();
        player.setTrackSelectionParameters(trackSelectionParameters);
        player.addListener(new PlayerEventListener());
        player.addAnalyticsListener(new EventLogger(trackSelector));
        player.setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */
        true);
        player.setPlayWhenReady(startAutoPlay);
        playerView.setPlayer(player);
        serverSideAdsLoader.setPlayer(player);
        debugViewHelper = new DebugTextViewHelper(player, debugTextView);
        debugViewHelper.start();
    }
    boolean haveStartPosition = startItemIndex != C.INDEX_UNSET;
    if (haveStartPosition) {
        player.seekTo(startItemIndex, startPosition);
    }
    player.setMediaItems(mediaItems, /* resetPosition= */
    !haveStartPosition);
    player.prepare();
    updateButtonVisibility();
    return true;
}
Also used : DebugTextViewHelper(androidx.media3.exoplayer.util.DebugTextViewHelper) EventLogger(androidx.media3.exoplayer.util.EventLogger) DefaultTrackSelector(androidx.media3.exoplayer.trackselection.DefaultTrackSelector) Intent(android.content.Intent) RenderersFactory(androidx.media3.exoplayer.RenderersFactory) ExoPlayer(androidx.media3.exoplayer.ExoPlayer)

Aggregations

EventLogger (androidx.media3.exoplayer.util.EventLogger)3 Intent (android.content.Intent)2 ExoPlayer (androidx.media3.exoplayer.ExoPlayer)2 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 FrameLayout (android.widget.FrameLayout)1 Toast (android.widget.Toast)1 Nullable (androidx.annotation.Nullable)1 C (androidx.media3.common.C)1 MediaItem (androidx.media3.common.MediaItem)1 Player (androidx.media3.common.Player)1 Assertions (androidx.media3.common.util.Assertions)1 GlUtil (androidx.media3.common.util.GlUtil)1 Util (androidx.media3.common.util.Util)1 DataSource (androidx.media3.datasource.DataSource)1 DefaultDataSource (androidx.media3.datasource.DefaultDataSource)1 DefaultHttpDataSource (androidx.media3.datasource.DefaultHttpDataSource)1