public ExoPlayerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); boolean useTextureView = false; ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); componentListener = new ComponentListener(); FrameLayout.LayoutParams aspectRatioParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); aspectRatioParams.gravity = Gravity.CENTER; layout = new AspectRatioFrameLayout(context); layout.setLayoutParams(aspectRatioParams); shutterView = new View(getContext()); shutterView.setLayoutParams(params); shutterView.setBackgroundColor(ContextCompat.getColor(context, android.R.color.black)); subtitleLayout = new SubtitleView(context); subtitleLayout.setLayoutParams(params); subtitleLayout.setUserDefaultStyle(); subtitleLayout.setUserDefaultTextSize(); View view = useTextureView ? new TextureView(context) : new SurfaceView(context); view.setLayoutParams(params); surfaceView = view; layout.addView(surfaceView, 0, params); layout.addView(shutterView, 1, params); layout.addView(subtitleLayout, 2, params); addViewInLayout(layout, 0, aspectRatioParams); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_player); media = (MediaFile) getIntent().getSerializableExtra(MEDIA); videoFragment = (VideoFragment) getFragmentManager().findFragmentById(R.id.playback_fragment); VideoFragmentGlueHost glueHost = new VideoFragmentGlueHost(videoFragment); subtitleView = (SubtitleView) findViewById(R.id.subtitle_view); if (subtitleView != null) { subtitleView.setUserDefaultStyle(); subtitleView.setUserDefaultTextSize(); } Handler mainHandler = new Handler(); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter); MappingTrackSelector trackSelector = new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); player.addListener(this); player.setTextOutput(this); glueHelper = new ExoPlayerGlue(player, trackSelector, this); glueHelper.setHost(glueHost); session = new MediaSession(this, "ITPlayer"); session.setCallback(new ExoPlayerMediaSessionCalback(player)); session.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); session.setActive(true); MediaMetadata.Builder metaBuilder = new MediaMetadata.Builder(); session.setMetadata(metaBuilder.build()); new SourceTask().execute(media); }
/** * Gets the {@link SubtitleView}. * * @return The {@link SubtitleView}, or {@code null} if the layout has been customized and the * subtitle view is not present. */ public SubtitleView getSubtitleView() { return subtitleView; }