BufferQueue has been abandoned: When playing video with TextureView

learner picture learner · Oct 22, 2015 · Viewed 18k times · Source

Every time I pause my activity (actually Fragment) to go to another app, upon returning with onResume I try to resume the video playing but it does not play: I get a blank screen. Upon investigation, I see the following in the Logcat

E/BufferQueueProducer: [unnamed-23827-0] queueBuffer: BufferQueue has been abandoned
E/MediaPlayer: error (1, -38)
E/MediaPlayer: error (1, -38)
E/MediaPlayer: error (1, -38)
E/MediaPlayer: error (1, -38)
E/BufferQueueProducer: [unnamed-23827-0] connect(P): BufferQueue has been abandoned

Here is the code I call inside on resume

player.seekTo(mVideoSeekPosition);
player.start();

FYI: I have been trying to apply this answer to my case, but I can't: What can I do when the BufferQueue has been abandoned?

UPDATE

I struggled to go it alone, but I am still crashing. So I am posting the whole code for help

private void setupVideoPlayingSystem(View root) {
  textureView = (TextureView) root.findViewById(R.id.textureView);
    
  textureView.setSurfaceTextureListener(this);
}
    
    
    

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
  Log.d(TAG, "onSurfaceTextureAvailable");
  if (null == surface) {
    Log.d(TAG, "new surface");
    surface = new Surface(surfaceTexture);
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setSurface(surface);
    mediaPlayer.setLooping(false);
  }
    
  /*
    
  outstandingVideoRequest is IOU for orentation change (verifed: onResume before onSurfaceTextureAvailable)
  but for cold startup, must check mVideoUrl
  */
    
  if (outstandingVideoRequest && null != mVideoUrl) {
    
    outstandingVideoRequest = false;

        playNewVideo(mVideoUrl);
  }
    
}
    
    

@Override
    
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
    
  Log.d(TAG, "onSurfaceTextureSizeChanged");

    }
    
    

@Override

    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
    
  Log.d(TAG, "onSurfaceTextureDestroyed");
  return false;//leave destruction for onDestroy
    
}

@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
        }
    

    private void playNewVideo(String url) {
        
      if (null == mediaPlayer || null == surface) {
        
        Log.d(TAG, "playNewVideo not ready");
    
            synchronized (outstandingVideoRequest) {
    
              Log.d(TAG, "playNewVideo outstandingVideoRequest");
    
               outstandingVideoRequest = true;
        }
         
      } else {
        
        try {
        
          mediaPlayer.reset();
        
          mediaPlayer.setDataSource(getContext(), Uri.parse(url));
        
          mediaPlayer.setLooping(false);
        
          mediaPlayer.prepareAsync();
         
          mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
        
            public void onPrepared(MediaPlayer player) {
        
              Log.d(TAG, "onPrepared changeMediaPlayerDatasource");
        
              onReadyToPlay(player);
            }
        
          });
        
       } catch (Exception e) {//IOException && IllegalStateException
        
         Log.d(TAG, "textureview playNewVideo ERORR");
        
         e.printStackTrace();
        
       }
        
        
     }
        
    }

  private void resumeVideoUponReturningFromAnotherActivity() {

            if (null == mediaPlayer || null == surface) {

                Log.d(TAG, "resumeVideoUponReturningFromAnotherActivity outstandingVideoRequest");

                outstandingVideoRequest = true;
    
        } else {
    
//            playNewVideo(mVideoUrl);

                Log.d(TAG, "resumeVideoUponReturningFromAnotherActivity go NOW");

                mediaPlayer.setSurface(surface);
    
            onReadyToPlay(mediaPlayer);

            }
    
    
    }
    
    

    private void onReadyToPlay(MediaPlayer player) {
    
        //play video
    
        mProgressCircle.setVisibility(View.GONE);

            showVideoOverlayChildren();
    
        if (0 == mVideoSeekPosition) {
    
            Log.d(TAG, "onReadyToPlay start");

                player.start();

            } else {
    
            Log.d(TAG, "onReadyToPlay seek");

                player.seekTo(mVideoSeekPosition);
     
           player.start();

            }
    
        mHandler.postDelayed(new Runnable() {

                @Override

                public void run() {

                    Log.d(TAG, "postDelayed resumeVideo");
    
                hideVideoOverlayChildren();

                }
    
        }, Constant.BEFORE_VIDEO_OVERLAY_DISAPPEAR);

        }


    
        private void destroyMediaPlayer() {

            if (null != mediaPlayer) {//move to video todo
    
            mediaPlayer.stop();

                mediaPlayer.release();
    
            mediaPlayer = null;

            }
    
        if (null != surface) {

                surface.release();

                surface = null;
    
        }
    
    }
    
    

    private void pauseVideo() {

            if (null != mediaPlayer) {

                Log.d(TAG, "pause");
    
            mediaPlayer.pause();

                mVideoSeekPosition = mediaPlayer.getCurrentPosition();

            }
    
    }


    
        private void stopVideo(){
    
        if (null != mediaPlayer) {

                Log.d(TAG, "stop video");

                mediaPlayer.pause();

                mVideoSeekPosition = mediaPlayer.getCurrentPosition();

                mediaPlayer.stop();

            }
    
    }

@Override
    public void onResume() {

        super.onResume();

        Log.d(TAG, "onResume");
    
    mLocalBroadcastManager.registerReceiver(mVideoSelectionReceiver, mVideoSelectedIntentFilter);
    
    resumeVideoUponReturningFromAnotherActivity();

    
    }

Answer

Joks picture Joks · Feb 25, 2016

I had the same problem when switched between activities and also had MediaPlayer(1971): Error (100,0). Solved it by adding these lines inside onSurfaceTextureDestroyed

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        if (mediaPlayer != null) {
            mediaPlayer.stop();
            mediaPlayer.release();
            mediaPlayer = null;
        }
        return true;
    }