Я хочу показать видео в просмотре Recycler, проблема в том, что когда я обменяюсь с первого видео и обратно на первое, первое перезагрузка видео снова, я хочу сделать все видео загружены одновременно, и когда я обменяюсь, сохраняет видео загруженное. эти строки в фрагменте => < /p>
Я хочу показать видео в просмотре Recycler, проблема в том, что когда я обменяюсь с первого видео и обратно на первое, первое перезагрузка видео снова, я хочу сделать все видео загружены одновременно, и когда я обменяюсь, сохраняет видео загруженное. эти строки в фрагменте => < /p> [code]// Setup StoryBoardAdapter val storyboardAdapter = StoryBoardAdapter(requireContext(), DataRepository.storyBoardList) val layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) binding.recyclerViewStoryBoard.layoutManager = layoutManager binding.recyclerViewStoryBoard.adapter = storyboardAdapter
// Attach PagerSnapHelper to show one item at a time val pagerSnapHelper = PagerSnapHelper() pagerSnapHelper.attachToRecyclerView(binding.recyclerViewStoryBoard) < /code> И это адаптер => < /p> class StoryBoardAdapter( private val context: Context, private val storyBoardList: List < /code> ): recyclerview.adapter () {< /p> companion object { private const val TYPE_IMAGE = 0 private const val TYPE_VIDEO = 1 private const val BASE_URL = "Link" }
private fun isVideo(url: String): Boolean { val lowerUrl = url.lowercase() return lowerUrl.endsWith(".mp4") || lowerUrl.endsWith(".webm") }
private fun getFullUrl(relativeUrl: String): String { return if (relativeUrl.startsWith("http")) relativeUrl else "$BASE_URL$relativeUrl" }
override fun getItemViewType(position: Int): Int { return if (isVideo(storyBoardList[position].imageEn)) TYPE_VIDEO else TYPE_IMAGE }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { return if (viewType == TYPE_IMAGE) { val view = LayoutInflater.from(parent.context) .inflate(R.layout.item_story_board_image, parent, false) ImageViewHolder(view) } else { val view = LayoutInflater.from(parent.context) .inflate(R.layout.item_story_board_video, parent, false) VideoViewHolder(view) } }
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { val item = storyBoardList[position]
// Check system or app language (you can replace with a stored preference if needed) val currentLanguage = context.resources.configuration.locales[0].language val imageUrl = if (currentLanguage == "ar") item.imageAr else item.imageEn val fullUrl = getFullUrl(imageUrl)
if (holder is ImageViewHolder) { Glide.with(holder.imageView.context) .load(fullUrl) .into(holder.imageView) } else if (holder is VideoViewHolder) { val videoUri = Uri.parse(fullUrl)