Issue
I'm trying to load videos from firebase storage to my recycler view with ExoPlayer. But the problem is that the video sometimes does not play and if i hit the play button it gives me this error below
Caused by: com.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed: OMX.MTK.VIDEO.DECODER.AVC......
I tried calling the release()
method after/before setting the player to the player view but nothing changed.
I have wasted over 5 days to fix this problem and i can't find any solution for it.
There is any ExoPlayer alternative to load videos from firebase to recycler view?
Part of code from onBindViewHolder inside my Recycler Adpater:
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
ExoPlayer player = new ExoPlayer.Builder(context).build();
MediaItem mediaItem = MediaItem.fromUri(postList.get(position).getImgUrl());
player.setMediaItem(mediaItem);
player.prepare();
videoViewHolder.andExoPlayerView.setPlayer(player);
}
And i'm initializing the playerView inside view holder like this:
public VideoViewHolder(@NonNull View itemView) {
super(itemView);
andExoPlayerView = itemView.findViewById(R.id.andExoPlayerView);
........
}
Solution
I had to release the player when the recycler view item are recycled
I find the answer from this question here
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
int position = holder.getAdapterPosition();
if (mDataset.get(position) != null) {
mDataset.get(position).getPlayer().release();
}
super.onViewRecycled(holder);
}
Answered By - GSepetadelis
Answer Checked By - Timothy Miller (JavaFixing Admin)