use of com.google.android.exoplayer2.ui.PlayerView in project ExoPlayer by google.
the class TransformerActivity method startTransformation.
@RequiresNonNull({ "playerView", "debugTextView", "informationTextView", "progressIndicator", "transformationStopwatch", "progressViewGroup", "debugFrame" })
private void startTransformation() {
requestTransformerPermission();
Intent intent = getIntent();
Uri uri = checkNotNull(intent.getData());
try {
externalCacheFile = createExternalCacheFile("transformer-output.mp4");
String filePath = externalCacheFile.getAbsolutePath();
@Nullable Bundle bundle = intent.getExtras();
Transformer transformer = createTransformer(bundle, filePath);
transformationStopwatch.start();
transformer.startTransformation(MediaItem.fromUri(uri), filePath);
this.transformer = transformer;
} catch (IOException e) {
throw new IllegalStateException(e);
}
informationTextView.setText(R.string.transformation_started);
playerView.setVisibility(View.GONE);
Handler mainHandler = new Handler(getMainLooper());
ProgressHolder progressHolder = new ProgressHolder();
mainHandler.post(new Runnable() {
@Override
public void run() {
if (transformer != null && transformer.getProgress(progressHolder) != Transformer.PROGRESS_STATE_NO_TRANSFORMATION) {
progressIndicator.setProgress(progressHolder.progress);
informationTextView.setText(getString(R.string.transformation_timer, transformationStopwatch.elapsed(TimeUnit.SECONDS)));
mainHandler.postDelayed(/* r= */
this, /* delayMillis= */
500);
}
}
});
}
use of com.google.android.exoplayer2.ui.PlayerView in project ExoPlayer by google.
the class TransformerActivity method playMediaItem.
@RequiresNonNull({ "playerView", "debugTextView" })
private void playMediaItem(MediaItem mediaItem) {
playerView.setPlayer(null);
releasePlayer();
ExoPlayer player = new ExoPlayer.Builder(/* context= */
this).build();
playerView.setPlayer(player);
player.setMediaItem(mediaItem);
player.play();
player.prepare();
this.player = player;
debugTextViewHelper = new DebugTextViewHelper(player, debugTextView);
debugTextViewHelper.start();
}
use of com.google.android.exoplayer2.ui.PlayerView 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;
}
use of com.google.android.exoplayer2.ui.PlayerView in project prebid-mobile-android by prebid.
the class XandrInstreamVideoGamActivity method initializePlayer.
private void initializePlayer() {
SimpleExoPlayer.Builder playerBuilder = new SimpleExoPlayer.Builder(this);
player = playerBuilder.build();
playerView.setPlayer(player);
adsLoader.setPlayer(player);
Uri uri = Uri.parse(getString(R.string.content_url));
MediaItem mediaItem = MediaItem.fromUri(uri);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, getString(R.string.app_name));
ProgressiveMediaSource.Factory mediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory);
MediaSource mediaSource = mediaSourceFactory.createMediaSource(mediaItem);
DataSpec dataSpec = new DataSpec(adsUri);
AdsMediaSource adsMediaSource = new AdsMediaSource(mediaSource, dataSpec, "ad", mediaSourceFactory, adsLoader, playerView);
player.setMediaSource(adsMediaSource);
player.setPlayWhenReady(true);
player.prepare();
}
use of com.google.android.exoplayer2.ui.PlayerView in project edx-app-android by edx.
the class PlayerFragment method onStart.
@Override
public void onStart() {
super.onStart();
logger.debug("Player fragment start");
try {
final PlayerView playerView = (PlayerView) getView().findViewById(R.id.player_view);
if (player != null) {
player.setPlayerView(playerView);
// setup the flat if player is fullscreen
player.setFullScreen(isScreenLandscape());
}
if (curMessageTypes.contains(VideoNotPlayMessageType.IS_VIDEO_ONLY_ON_WEB)) {
showVideoNotAvailable(VideoNotPlayMessageType.IS_VIDEO_ONLY_ON_WEB);
}
if (curMessageTypes.contains(VideoNotPlayMessageType.IS_VIDEO_MESSAGE_DISPLAYED)) {
showVideoNotAvailable(VideoNotPlayMessageType.IS_VIDEO_MESSAGE_DISPLAYED);
} else if (curMessageTypes.contains(VideoNotPlayMessageType.IS_NETWORK_MESSAGE_DISPLAYED)) {
showNetworkError();
} else if (curMessageTypes.contains(VideoNotPlayMessageType.IS_SHOWN_WIFI_SETTINGS_MESSAGE)) {
showWifiSettingsMessage();
}
} catch (Exception e) {
logger.error(e);
}
}
Aggregations