How can we use multiple exo player in a recycler view? I saw many posts and videos like this and this but that all use a custom recycler view class. I could continue with that. But, I wanted to make a complete Insta clone where I can send gif and image and videos. Now, when I use the custom recycler view class, I dont have any idea of how to play the video with the gif and images. This is my recycler view item code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="10dp"
app:cardCornerRadius="6dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.sambhav2358.facebookclone.customviews.RoundedImageView
android:id="@+id/senderImage"
android:layout_width="50dp"
android:layout_height="50dp"
app:cornerRadius="100dp"
android:src="@color/primary"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginStart="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/senderName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Sender name"
android:ellipsize="end"
android:textStyle="bold"
android:textColor="@color/black"
android:layout_weight="1"/>
<TextView
android:id="@+id/dateAdded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date added"
android:ellipsize="end"
android:layout_marginStart="10dp"/>
</LinearLayout>
<TextView
android:id="@+id/senderUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sender user name"
android:ellipsize="end"
android:textColor="@color/black"
android:layout_weight="1"/>
</LinearLayout>
<ImageView
android:id="@+id/more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/more"
android:layout_marginStart="5dp"
android:padding="4dp"
android:background="?selectableItemBackgroundBorderless"/>
</LinearLayout>
<TextView
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Body\nOf\nThe\nPost"
android:layout_margin="10dp"/>
<androidx.cardview.widget.CardView
android:id="@+id/postExtra"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_margin="5dp"
app:cardCornerRadius="6dp"
app:cardElevation="0dp">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="200dp" />
<ImageView
android:id="@+id/imageVIew"
android:layout_width="match_parent"
android:layout_height="200dp" />
<com.giphy.sdk.ui.views.GifView
android:id="@+id/gifView"
android:layout_width="match_parent"
android:layout_height="200dp"/>
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:cardCornerRadius="50dp"
android:backgroundTint="@color/primary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="10dp"
android:paddingVertical="5dp"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/like"
app:tint="@android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Like"
android:textColor="@color/white"
android:layout_gravity="center"
android:layout_marginStart="10dp"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<View
android:layout_width="10dp"
android:layout_height="0dp"/>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:cardCornerRadius="50dp"
android:backgroundTint="@color/primary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="10dp"
android:paddingVertical="5dp"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/share"
app:tint="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Share"
android:textColor="@color/white"
android:layout_gravity="center"
android:layout_marginStart="10dp"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<View
android:layout_width="10dp"
android:layout_height="0dp" />
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:cardCornerRadius="50dp"
android:backgroundTint="@color/primary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="10dp"
android:paddingVertical="5dp"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/comment"
app:tint="@android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comment"
android:textColor="@color/white"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
RecyclerView
? u will be using a separate layout for these items with a Scroll listener so that if an video item goes out of the screen you can stop the video.