Search in sources :

Example 1 with EventLogger

use of com.google.android.exoplayer2.util.EventLogger in project ExoPlayer by google.

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(com.google.android.exoplayer2.util.DebugTextViewHelper) EventLogger(com.google.android.exoplayer2.util.EventLogger) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) Intent(android.content.Intent) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) ExoPlayer(com.google.android.exoplayer2.ExoPlayer)

Example 2 with EventLogger

use of com.google.android.exoplayer2.util.EventLogger 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 3 with EventLogger

use of com.google.android.exoplayer2.util.EventLogger in project ExoPlayer by google.

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(com.google.android.exoplayer2.util.EventLogger) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager)

Aggregations

EventLogger (com.google.android.exoplayer2.util.EventLogger)3 Intent (android.content.Intent)2 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)2 DrmSessionManager (com.google.android.exoplayer2.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 (com.google.android.exoplayer2.C)1 MediaItem (com.google.android.exoplayer2.MediaItem)1 Player (com.google.android.exoplayer2.Player)1 RenderersFactory (com.google.android.exoplayer2.RenderersFactory)1 DefaultDrmSessionManager (com.google.android.exoplayer2.drm.DefaultDrmSessionManager)1 FrameworkMediaDrm (com.google.android.exoplayer2.drm.FrameworkMediaDrm)1 HttpMediaDrmCallback (com.google.android.exoplayer2.drm.HttpMediaDrmCallback)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 ProgressiveMediaSource (com.google.android.exoplayer2.source.ProgressiveMediaSource)1