com.google.android.exoplayer2.ui.PlaybackControlView Java Examples

The following examples show how to use com.google.android.exoplayer2.ui.PlaybackControlView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExoPlayerFragment.java    From carstream-android-auto with Apache License 2.0 4 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    titleView = view.findViewById(R.id.player_title);
    albumView = view.findViewById(R.id.player_album);
    playerView = view.findViewById(R.id.exoplayer_view);
    playerView.setControllerVisibilityListener(new PlaybackControlView.VisibilityListener() {
        @Override
        public void onVisibilityChange(int visibility) {
            titleView.setVisibility(visibility);
            albumView.setVisibility(visibility);
            mListener.onNativePlayerControlsVisibilityChange(visibility);
        }
    });
    player = ExoPlayerFactory.newSimpleInstance(
            new DefaultRenderersFactory(getContext()),
            new DefaultTrackSelector(),
            new DefaultLoadControl());
    playerView.setPlayer(player);
    playerView.requestFocus();
    player.setPlayWhenReady(true);
    playerQueue = new PlayerQueue(filePath);
    MediaSource mediaSource = buildMediaSource(playerQueue);
    player.seekToDefaultPosition(playerQueue.currentIndex());
    player.prepare(mediaSource, true, false);
    player.addListener(this);
    setAspectRatio(mListener.getAspectRatio());
    playerFocusHelper = new PlayerFocusHelper(getContext()) {
        @Override
        protected void onStop() {
            super.onStop();
            player.setPlayWhenReady(false);
        }

        @Override
        protected void onPause() {
            super.onPause();
            player.setPlayWhenReady(false);
        }

        @Override
        public boolean isPlaying() {
            return player.getPlayWhenReady();
        }

        @Override
        protected void onPlay() {
            super.onPlay();
            player.setPlayWhenReady(true);
        }
    };


}
 
Example #2
Source File: VideoPlayerActivity.java    From Camera-Roll-Android-App with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video_player);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    Intent intent = getIntent();
    videoUri = intent.getData();

    if (videoUri == null) {
        return;
    }

    //needed to achieve transparent navBar
    showOrHideSystemUi(true);

    //init Play pause button
    final ImageButton playPause = findViewById(R.id.play_pause);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        playPause.setImageResource(R.drawable.pause_to_play_avd);
    } else {
        playPause.setImageResource(R.drawable.ic_pause_white);
    }

    playPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (player != null) {
                player.setPlayWhenReady(!player.getPlayWhenReady());
            }
        }
    });


    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    setWindowInsets();

    //hide & show Nav-/StatusBar together with controls
    final PlaybackControlView playbackControlView = (PlaybackControlView)
            findViewById(R.id.playback_control_view).getParent();
    final View bottomBarControls = findViewById(R.id.controls);
    playbackControlView.setVisibilityListener(
            new PlaybackControlView.VisibilityListener() {
                @Override
                public void onVisibilityChange(final int i) {
                    //animate Toolbar & controls
                    if (i != View.VISIBLE) {
                        //make view visible again, so the Animation is visible
                        playbackControlView.setVisibility(View.VISIBLE);
                    }

                    float toolbar_translationY = i == View.VISIBLE ? 0
                            : -(toolbar.getHeight());
                    toolbar.animate()
                            .translationY(toolbar_translationY)
                            .setInterpolator(new AccelerateDecelerateInterpolator())
                            .setListener(new AnimatorListenerAdapter() {
                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    super.onAnimationEnd(animation);
                                    playbackControlView.setVisibility(i);
                                }
                            })
                            .start();

                    float controls_translationY = i == View.VISIBLE ? 0
                            : bottomBarControls.getHeight();
                    bottomBarControls.animate()
                            .translationY(controls_translationY)
                            .setInterpolator(new AccelerateDecelerateInterpolator())
                            .start();

                    //show/hide Nav-/StatusBar
                    showOrHideSystemUi(i == View.VISIBLE);
                }
            });
}