从URL显示视频缩略图

时间:2013-03-23 11:19:59

标签: java android video-streaming

好吧这可能是一个愚蠢的,但请原谅我,因为我是Android的新手。我正在开发一个应用程序,我想在其中使用远程URL显示视频缩略图:

视频网址: http://173.193.24.66/~kanz/video/flv/9.flv

.JPG网址:     http://173.193.24.66/~kanz/video/Images/9.jpg

我想要在SQL数据库中存储的缩略图上显示视频网址和图像文件网址。唯一的问题是我不知道如何将它们放在ScrollView中的List视图中。我尝试在互联网上搜索,但他们似乎都提供了如何从SD卡路径显示视频缩略图的教程。我想使用这些URL中的任何一个来显示视频缩略图。 我听说过API,但由于Youtube在我的国家被禁止,我无法使用Youtube API。如果有人知道任何有用的API或任何其他黑客,请告诉我。非常感谢。我正在使用姜饼。

3 个答案:

答案 0 :(得分:0)

那些教程是正确的,但你错过了一步。您需要先使用URL将这些图像下载到设备。然后,您可以将它们设置为在列表视图中查看。

在这些主题中了解如何执行此操作:

有一个流行的开源库可以自动处理图像的下载和缓存。看看:

https://github.com/koush/UrlImageViewHelper

答案 1 :(得分:0)

Listview有自己的卷轴。所以不要将listview放在滚动视图中。

使用自定义列表视图显示缩略图。

从网址中获取您的网址。

http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

http://www.youtube.com/watch?v=wDBM6wVEO70。谈论的是关于列表视图和性能。

使用观看者。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);

答案 2 :(得分:0)

将这些行添加到您的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*/);
相关问题