ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Player gone black with error MediaCodecRenderer$DecoderInitializationException after some scrolling ups and down

Open parthbhatti opened this issue 4 years ago • 3 comments

I have recyclerview with Exoplayer instance.The recyclerview has been set up as 1 video per page (Full screen) with scrolling.

when I scroll 10 to 12 videos It goes black with error MediaCodecRenderer$DecoderInitializationException

Here is my recyclerview code.


@Override
    public void onBindViewHolder(final Home_Adapter.CustomViewHolder holder, final int i) {
        final Home_Get_Set item = dataList.get(i);
        holder.setIsRecyclable(false);

        try {


            //to avoid refreshing player when notifyDataStateChanged() called
            if(holder.playerview.getPlayer() != null)
            {
                return;
            }


            int MIN_BUFFER_DURATION = 2000;

            int MAX_BUFFER_DURATION = 5000;

            int MIN_PLAYBACK_START_BUFFER = 1500;

            int MIN_PLAYBACK_RESUME_BUFFER = 2000;

            LoadControl loadControl = new DefaultLoadControl.Builder()
                    .setAllocator(new DefaultAllocator(true, 16))
                    .setBufferDurationsMs(MIN_BUFFER_DURATION,
                            MAX_BUFFER_DURATION,
                            MIN_PLAYBACK_START_BUFFER,
                            MIN_PLAYBACK_RESUME_BUFFER)
                    .setTargetBufferBytes(-1)
                    .setPrioritizeTimeOverSizeThresholds(true).createDefaultLoadControl();


            final SimpleExoPlayer player = new SimpleExoPlayer.Builder(context).setLoadControl(loadControl).build();

            DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context,
                    Util.getUserAgent(context, "myapp"));

            MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
                    .createMediaSource(Uri.parse(item.video_url));

            Log.d("resp", item.video_url);


            player.prepare(videoSource);

            player.setPlayWhenReady(false);
            player.setRepeatMode(Player.REPEAT_MODE_ALL);

           holder.playerview.setPlayer(player);




        } catch (Exception e) {

        }
    }



  @Override
    public void onViewRecycled(@NonNull CustomViewHolder holder) {
        int position = holder.getAdapterPosition();
        if (holder.playerview.getPlayer() != null) {
            holder.playerview.getPlayer().release();
        }
        super.onViewRecycled(holder);
    }

    @Override
    public void onViewAttachedToWindow(@NonNull CustomViewHolder holder) {
        super.onViewAttachedToWindow(holder);
        try {
            holder.playerview.getPlayer().setPlayWhenReady(true);
        } catch (Exception e) {

        }
    }

    @Override
    public void onViewDetachedFromWindow(@NonNull CustomViewHolder holder) {
        super.onViewDetachedFromWindow(holder);
        try {
            holder.playerview.getPlayer().setPlayWhenReady(false);
            holder.playerview.getPlayer().release();
            holder.playerview.setPlayer(null);
        } catch (Exception e) {

        }

    }

parthbhatti avatar Jun 09 '20 11:06 parthbhatti

Is this because of holder.setIsRecyclable(false) or Recyclerview.hasStableIds = true?

May be exo player is not releasing player successfully. I am preparing 10 players at a time

parthbhatti avatar Jun 15 '20 17:06 parthbhatti

No solutions? I am struggling with this issue for a month.

If there is a limit in Exo player instance why it's not releasing it in Recyclerview, It's working fine over fragments and Activities

parthbhatti avatar Jun 26 '20 05:06 parthbhatti

There are quite a few existing issues discussing this problem, and also some sample solutions posted in those issues. For example: https://github.com/google/ExoPlayer/issues/867.

Have you given them a read? At a high level, yes, you should try and limit the number of instances you use. If only one video is playing at once, ideally you should limit the number of instances to 1.

ojw28 avatar Jun 26 '20 10:06 ojw28