好吧,这可能是一个愚蠢的,但请原谅我,因为我是Android的新手。我正在开发一个应用程序,我希望使用远程URL显示视频缩略图,例如:
视频网址:http://173.193.24.66/~kanz/video/flv/9.flv
.JPG网址:http://173.193.24.66/~kanz/video/Images/9.jpg
我有想要在SQL数据库中存储的缩略图上显示的视频URL和图像文件URL。唯一的问题是我不知道如何将它们放在ScrollView中的List视图中。我尝试在互联网上搜索,但他们似乎都提供了如何从SD卡路径显示视频缩略图的教程。我想使用这些URL中的任何一个来显示视频缩略图。我听说过API,但由于Youtube在我的国家被禁止,我无法使用Youtube API。如果有人知道任何有用的API或任何其他黑客,请告诉我。非常感谢。我正在使用姜饼。
Listview有自己的卷轴。所以不要将listview放在滚动视图中。
使用自定义列表视图显示缩略图。
从数据库中获取你的卷发。
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
http://www.youtube.com/watch?v=wDBM6wVEO70。谈论的是listview和性能。
使用viewholder.http://developer.android.com/training/improving-layouts/smooth-scrolling.html。
如果要在listview中显示大量图像,请考虑使用以下库之一。
1.Universal Image loader。 https://github.com/nostra13/Android-Universal-Image-Loader。
2.Lazy List。 https://github.com/thest1/LazyList。
两者都使用缓存。
适用于通用图像加载器
在适配器构造函数中
File cacheDir = StorageUtils.getOwnCacheDirectory(a, "UniversalImageLoader/Cache");
imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a)
// You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.enableLogging()
.build();
// Initialize ImageLoader with created configuration. Do it once.
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_id)//dummy image
.cacheInMemory()
.cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(20))
.build();
在你的getview()
ImageView image=(ImageView)vi.findViewById(R.id.imageview);
imageLoader.displayImage(imageurl, image,options);
这些教程是正确的,但你错过了一步。您需要先使用URL将这些图像下载到设备。然后,您可以将它们设置为在列表视图中查看。
在这些线程中查看如何执行此操作:
有一个流行的开源库,可以自动处理图像的下载和缓存。看看这个:
将这些行添加到Module:app gradle
:
dependencies {
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
// pass video url into .load() method
Glide.with(context)
.asBitmap()
.load(/*Video Url*/)
.into(/*Name of Imageview*/);