ExoPlayer stop/pause not working

android exoplayer play/pause listener
exoplayer pause
exoplayer stop buffering
exoplayer seek
exoplayer tutorial
exoplayer kotlin
exoplayer androidx
exoplayer in recyclerview

I have added ExoPlayer in one of the activity to play videos and it is working properly. But when the video is playing and user presses back button, the video still continue to play in background. I want it to be stopped. I tried capturing the back button and tried pausing the video but it is not working. Unless you kill the activity, the video keeps on playing until it is finished. Is it a bug or this is how the library is supposed to work?

Here is working code of expPlayr

    String url = getIntent().getStringExtra("videoURL");
    String title = getIntent().getStringExtra("title");
    exoPlayerView = (SimpleExoPlayerView) findViewById(R.id.exo_player_id);

    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();

    TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));

    exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);

    DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory(title);
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    MediaSource m = new HlsMediaSource(Uri.parse(url), dataSourceFactory, null,null);


Here is the code I'm trying to use to stop the video.

    public void onBackPressed(){

        }catch(Exception e){

I review the code in debug mode and this statement is executed, but still not stopping the video.

try this...

if (exoPlayer != null) {

Android Question, Hello, I have added ExoPlayer in one of the activity to play videos and it is working properly. But when the video is playing and user presses  I have added ExoPlayer in one of the activity to play videos and it is working properly. But when the video is playing and user presses back button, the video still continue to play in background. I want it to be stopped. I tried capturing the back button and tried pausing the video but it is not working.

My code is working for audio activity:

public void release() {

    if (exoPlayer != null) {
        exoPlayer = null;
        dataSpec =null;
        assetDataSource = null;
        factory = null;
        audioSource =null;

public void onBackPressed() {
    // TODO Auto-generated method stub


Notification stop button is not visible when multiple track is playing , Exo player shows stop button in notification just when single track pass to it. GitHub is home to over 50 million developers working together to host and PLAY/PAUSE; FAST_FORWARD; SKIP_TO_NEXT; STOP (often not  Exoplayer stops looping. Ask Question Asked 2 years, 2 months ago. Active 1 year, 10 months ago. ExoPlayer stop/pause not working. Hot Network Questions

You can use the example of exoplayer, releasePlayer method:

private void releasePlayer() {
        if (player != null) {
            player = null;
            trackSelector = null;
            trackSelectionHelper = null;
            eventLogger = null;

See PlayerActivity class in ExoPlayer demo.

Restarting playback after calling stop() · Issue #27 · google/ExoPlayer, Has anyone else had a problem with starting local playback again after calling stop()? I'm running a few test cases and have found that  I use exoplayer in my fragment. I had tried what you say , but it takes about 10 seconds even worse when bad network. I think it is not a good citizen too because user can't see anything except a black frame.

I'd recommend to initialize and release the player in life-cycle methods of the Activity. If you do this properly you don't need the onBackPressed method, because your code is executed in the lifecycle methods.

The PlayerActivity of the ExoPlayer demo application on Github has essentially these lifecycle methods:

public void onStart() {
  if (Util.SDK_INT > 23) {

public void onResume() {
  if (Util.SDK_INT <= 23 || player == null) {

public void onPause() {
  if (Util.SDK_INT <= 23) {

public void onStop() {
  if (Util.SDK_INT > 23) {

ExoPlayer Resume Method not working properly - Bugs, instead of resuming where it left off. Steps to reproduce the issue Click Start Click Pause Click Resume Expected Behaviour Resume sho… ExoPlayer will not follow this redirect in its default configuration, meaning playback will fail. If you need to, you can configure ExoPlayer to follow cross-protocol redirects when instantiating the HttpDataSource.Factory instances used by ExoPlayer in your application.

I also went through same issue in my project. The issue I had was - Exoplayer is initialized twice when screen is loaded and one instance is released when we call realeseExoplayer() in onPause or onResume() as per SDK version. The second instance continues to play in the background even when activity is closed. So request to double check whether Exoplayer is initialized twice or not. If it is initialized more than once, make necessary changes to initialize it once.

1382151, [Fennec][HLS] Pause ExoPlayer when player is paused to avoid OOM. Fork from Bug 1379866 comment 12, Switching tab will not invoke should resume Exoplayer to get the enough chunks and pause again when it stop fetching data. { Log.d(LOGTAG, "loading [" + isLoading + "]"); } > if (!isLoading) { Shouldn't we call  For the use case shown in your example, I think what should happen is that the position should stop counting up, but the play/pause button should not change (i.e. it should continue to represent the opposite to the user intention - i.e. continue to be the pause button).

Easy Audio Focus with ExoPlayer - google-exoplayer, However, after you acquire audio focus you may not be able to keep it until If that happens your app should pause playing or lower its volume to let users Working with ExoPlayer — The clean way — and customization. ExoPlayer's duration is 0 and seekTo not working. On "Big buck bunny" video, only seekTo not working, duration not 0. VLC's duration is 0, but seekTo works fine by percent parameter. On "Big buck bunny video", pause works as stop - video starts from the begining, duration not 0.

SimpleExoPlayer (ExoPlayer library), Whether the player is currently loading the source. boolean, isPlayingAd() Sets whether the player should pause automatically when audio is rerouted from a headset to device speakers. Stops playback and optionally resets the player. I am developing streaming application, so for that i am using exoplayer. This is the code.It is working everything fine.But I need to show notification along with title and play/pause button. This play/pause button must work like activity play/pause button and this play/pause button must change as per play/pause.

Media streaming with ExoPlayer - Codelabs, ExoPlayer is the video player running in the Android YouTube app. Screenshot: The YouTube Android app. ExoPlayer is an application level media player built  Hi, I am developing an android app, and for playing videos, I am using Ex-player. But I was stuck into a problem that exoplayer doesn&#39;t start on its own. I have to click the play button then on

  • plus one for passing source code on github for a full understanding..