How Do I Play Video in ListView like Instagram and Vine?

后端 未结 2 1275
广开言路
广开言路 2021-02-20 07:16

I\'m new to android development and I am trying to play multiple videos in a listview. Currently, each listview row item is a VideoView. This approach has not worked as the Vi

2条回答
  •  离开以前
    2021-02-20 07:47

    For playing videos in Listview, you need to open Video on Item Click of ListView then you can retrieve your video url in String like:

    String  myUrl = urHashMaparraylist.get(position).get("videolocation");
    

    Now pass this myUrl to next Activity and just set this String as a

     Uri video = Uri.parse(myUrl);
     videoView.setVideoURI(video);
    
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView parent, View view, int position, long id) 
         {
            String  myUrl = urHashMaparraylist.get(position).get("videolocation");
            Intent n = new Intent(YourActivityName.this , NewActivityName.class);
            n.putExtra("videolocation",myUrl);
            startActivity(n);    
        }
    
    });
    

    Now in your next Activity retrieve it as a

    Uri video = Uri.parse(url);
    videoView.setVideoURI(video);
    

    In some case, for setting VideoView,you can use:

     android:background:"#0000"
    

    as from Android Scrollview having videoview is giving problem

    Instead of VideoView you can also try using TextureView for reference you can see number 2 reference:

    For more reference for video streaming ... you can check the following url: 1>http://developer.samsung.com/android/technical-docs/Android-Media-Streaming-Tutorial

    2>http://developer.android.com/reference/android/view/TextureView.html

提交回复
热议问题