Click here to Skip to main content
15,308,532 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have been working on a video where were people can watch videos like tik tok. At first I made it with recyclerview and later on I realized that I should use Vertical Viewpager. At first I used Viewpager2 but I faced some problems so I replaced it with viewpager1. But still it is not working. I am doing this in my fragment. I want to play videos from firebase in Vertical viewpager using videoview. In Viewpager_Adapter u can see that I have called one more layout there which is viewer_page but when I run my app I don't get that layout in my fragment


 class ViewpagerAdapter(var context: Context) : PagerAdapter() {
    lateinit var inflater: LayoutInflater
    var contentDTOs: ArrayList<ContentDTOs> = arrayListOf()

    var contentUidList: ArrayList<String> = arrayListOf()

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object` as ConstraintLayout
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object`as ConstraintLayout)
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        inflater = context.getSystemService(container.context.toString())as LayoutInflater
        val view =inflater.inflate(R.layout.viewer_page,container,false)
        val exo : View? = view?.findViewById(R.id.videoviews)

        val path = Uri.parse(contentDTOs[position].videourl)
        val views = view.findViewById<VideoView>(R.id.videoviews)
        views.setVideoURI(path)
        views.requestFocus()
        views.setOnPreparedListener {
            views.start()
        }
        container.addView(view)
        return view
    }

    override fun getCount(): Int {
        return contentDTOs.size
    }
}


Watch_video_fragment

    @SuppressLint("ResourceAsColor")
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        val fragmentview = inflater.inflate(R.layout.fragment_watch_video, container, false)
        fragmentview.videofragment?.setOnClickListener {
            var fragment = Watch_video()
            activity?.supportFragmentManager?.beginTransaction()?.replace(R.id.frag, fragment)
                ?.commit()

        }
        fragmentview.memefragment?.setOnClickListener {
            var fragment = DetailViewFragment()
            activity?.supportFragmentManager?.beginTransaction()?.replace(R.id.frag, fragment)
                ?.commit()

        }


        firestore = FirebaseFirestore.getInstance()
        uid = FirebaseAuth.getInstance().currentUser?.uid

        fragmentview.videofragment?.setOnClickListener {
            var fragment = Watch_video()
            activity?.supportFragmentManager?.beginTransaction()?.replace(R.id.frag, fragment)
                ?.commit()

        }
//


        fragmentview.vertical_viewpager.adapter = ViewpagerAdapter(requireContext())
        fragmentview.vertical_viewpager.setPageTransformer(false
        ) { page, position ->
            page.rotationY = position * -30 // animation style... change as you want..
        }


Can u guys plz help me

What I have tried:

I have tried to play videos from firebase to videoview using vertical viewpager
Posted
Updated 5-Nov-20 16:24pm
v3
Comments
Richard Deeming 5-Nov-20 10:16am
   
"Is not working" is not a sufficient description of the problem for anyone to help you.

Click the green "Improve question" link and update your question to include a complete description of the problem. Include the full details of any errors.
Member 14883729 5-Nov-20 22:23pm
   
Ok done. U can check if u need anymore information.
wseng 7-Nov-20 11:18am
   
Did you add viewpager in fragment_watch_video.xml?
Member 14883729 10-Nov-20 5:18am
   
Yes
wseng 11-Nov-20 4:54am
   
can you show us how your xml look like?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900