简体   繁体   English

如何在 android 中使用不同幻灯片持续时间的 ViewPager 幻灯片图片和视频?

[英]How to use ViewPager slideshow images and videos with different slide time duration in android?

I am looking for a solution to create a slider show in android. I want to mix the video and image with it with different time duration like each item having own time duration like 10 secs or 20 secs.我正在寻找一种在 android 中创建 slider 节目的解决方案。我想将视频和图像与不同的持续时间混合,就像每个项目都有自己的持续时间,如 10 秒或 20 秒。 I only found how to create a image only slider show.我只发现如何创建图像只有 slider 显示。

You can register OnPageChangeCallback and on every onPageSelected(psoition: Int) you can check for the position < adapter.itemCount and use viewPager.currentItem = position + 1 or viewPager.currentItem = 0 when you have reached the last item.您可以注册OnPageChangeCallback并在每个onPageSelected(psoition: Int)上检查position < adapter.itemCount并在到达最后一项时使用viewPager.currentItem = position + 1viewPager.currentItem = 0

For the CountDownTimer you can use the time whatever you want like you can hard code it to 20 sec or you can use adapter to get the current item, check for the type, fetch the video duration with the MediaMetadataRetriever class. Do whatever fits your requirement.对于CountDownTimer ,您可以随意使用时间,例如您可以将其硬编码为 20 秒,或者您可以使用adapter获取当前项目,检查类型,使用MediaMetadataRetriever class 获取视频持续时间。做任何适合您的要求.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM