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;
}
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();
}
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;
}
Aggregations