1

Getting error in MediaController(this) as i had used this in the adapter class to display video in recycler view. Can you please help me find the cause of the error I get?

This is my implementation:

class VersionAdapter(val versionList:List<Versions>):RecyclerView.Adapter<VersionAdapter.VersionVM>() {

  class VersionVM (itemView: View):RecyclerView.ViewHolder(itemView){

    var codeNameText:TextView=itemView.findViewById(R.id.codename)
    var video11:VideoView=itemView.findViewById(R.id.version)
    var linearLayout:LinearLayout=itemView.findViewById(R.id.linearLayout)
    var expandable_layout:RelativeLayout=itemView.findViewById(R.id.expandable_layout)
  }

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VersionVM {
    val view:View=LayoutInflater.from(parent.context).inflate(R.layout.list_item,parent,false)
    return VersionVM(view)
  }


  override fun onBindViewHolder(holder: VersionVM, position: Int) {
    val versions:Versions=versionList[position]
    holder.codeNameText.text=versions.videoName
    holder.video11.setVideoURI(Uri.parse(versions.version.toString()))

    holder.video11.start()


    val isExpandable:Boolean=versionList[position].expandable
    holder.expandable_layout.visibility=if (isExpandable) View.VISIBLE else View.GONE
    holder.linearLayout.setOnClickListener {
        val versions = versionList[position]
        versions.expandable = !versions.expandable
        notifyItemChanged(position)
    }
 }
}

Thanks in advance!

Marcel Hofgesang
  • 951
  • 1
  • 15
  • 36
  • Code example would be useful to help you – Marcel Hofgesang May 03 '21 at 08:07
  • 1
    override fun onBindViewHolder(holder: VersionVM, position: Int) { val versions:Versions=versionList[position] holder.codeNameText.text=versions.videoName holder.video11.setVideoURI(Uri.parse(versions.version.toString())) val mediaController=MediaController(this) mediaController.setAnchorView(holder.video11); holder.video11.setMediaController(mediaController); holder.video11.start() – ąąʂɧıɱą ąɱıɧ May 03 '21 at 08:23
  • Better add this code to your question instead to comments for better readability. – Marcel Hofgesang May 03 '21 at 08:33
  • 1
    Where to add the media controller here? As i have my videoview in the listItem_xml – ąąʂɧıɱą ąɱıɧ May 03 '21 at 08:45
  • What you wanna do with media controller? Please be more precise regarding your intention and question. Also it would be nice if you format your code to match with the indentation of your IDE or at least accept edit suggestions. – Marcel Hofgesang May 03 '21 at 10:21
  • Media controller is to control your videos, And I had completed that by using the context... And thank you!!! – ąąʂɧıɱą ąɱıɧ May 05 '21 at 14:57

0 Answers0