use of com.google.android.exoplayer2.trackselection.ExoTrackSelection in project Slide by ccrama.
the class ExoVideoView method setupPlayer.
/**
* Initializes the view to render onto and the SimpleExoPlayer instance
*/
private void setupPlayer() {
// Create a view to render the video onto and an AspectRatioFrameLayout to size the video correctly
AspectRatioFrameLayout frame = new AspectRatioFrameLayout(context);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
params.addRule(CENTER_IN_PARENT, TRUE);
frame.setLayoutParams(params);
frame.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
SurfaceView renderView = new SurfaceView(context);
frame.addView(renderView);
addView(frame);
// Create a track selector so we can set specific video quality for DASH
trackSelector = new DefaultTrackSelector(context);
if ((SettingValues.lowResAlways || (NetworkUtil.isConnected(context) && !NetworkUtil.isConnectedWifi(context) && SettingValues.lowResMobile)) && SettingValues.lqVideos) {
trackSelector.setParameters(trackSelector.buildUponParameters().setForceLowestBitrate(true));
} else {
trackSelector.setParameters(trackSelector.buildUponParameters().setForceHighestSupportedBitrate(true));
}
// Create the player, attach it to the view, make it repeat infinitely
player = new SimpleExoPlayer.Builder(context).setTrackSelector(trackSelector).build();
player.setVideoSurfaceView(renderView);
player.setRepeatMode(Player.REPEAT_MODE_ALL);
// Mute by default
player.setVolume(0f);
// Create audio focus helper
audioFocusHelper = new AudioFocusHelper(ContextCompat.getSystemService(context, AudioManager.class));
player.addListener(new Player.Listener() {
// Make the video use the correct aspect ratio
@Override
public void onVideoSizeChanged(@NonNull VideoSize videoSize) {
frame.setAspectRatio(videoSize.height == 0 || videoSize.width == 0 ? 1 : videoSize.width * videoSize.pixelWidthHeightRatio / videoSize.height);
}
// Logging
@Override
public void onTracksChanged(@NonNull TrackGroupArray trackGroups, @NonNull TrackSelectionArray trackSelections) {
StringBuilder toLog = new StringBuilder();
for (int i = 0; i < trackGroups.length; i++) {
for (int j = 0; j < trackGroups.get(i).length; j++) {
toLog.append("Format:\t").append(trackGroups.get(i).getFormat(j)).append("\n");
}
}
// FIXME: How do I make onTracksChanged work with ExoTrackSelection?
/*for (TrackSelection i : trackSelections.getAll()) {
if (i != null)
toLog.append("Selected format:\t").append(i.getSelectedFormat()).append("\n");
}*/
Log.v(LogUtil.getTag(), toLog.toString());
}
});
}
Aggregations