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

て烟熏妆下的殇ゞ 提交于 2019-12-04 02:54:17

Although the answer is late but i think it might help someone searching for the same. There is a sample app from the github that has implementation for this requirement.:-

https://github.com/danylovolokh/VideoPlayerManager

For understanding of code refer to the following link it is really helpful for you:-

https://medium.com/@v.danylo/implementing-video-playback-in-a-scrolled-list-listview-recyclerview-d04bc2148429

The problem is that there are some limitations in VideoView in listview and handling playbacks so this library implement is the VideoView based on the TextureView. Here is it how it looks like

SID --- Choke_de_Code

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!