它可以在Android 4.0或以上显示来自URL的视频缩略图? [英] It is possible to display a video thumbnail from a URL on Android 4 and above?
问题描述
这两个以下正常工作在模拟器(2.3.3),而是一个真正的设备上(的Nexus小号 4.1.2)没有图像显示为缩略图。我也将尝试在的Android 4.0模拟器
运行。如果我设置一个默认的机器人:SRC
为的ImageView
,它不显示了呢。这让我觉得,它被替换,但的ImageView
是空的。
Both of the below works fine on the emulator (2.3.3), but on a real device (Nexus S with 4.1.2) no image is shown for the thumbnail. I will also try to run it on an Android 4 Emulator
. If I set a default android:src
for the ImageView
, it is not shown anymore then. This makes me think that it is replaced, but the ImageView
is empty.
public class MainActivity extends Activity {
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = (ImageView)findViewById(R.id.img_thumbnail);
new MyAsync().execute("http://commonsware.com/misc/test.mp4");
}
//This version is still not working, but it's more readable (edited: Selvin).
public class MyAsync extends AsyncTask<String, Void, Bitmap>{
@Override
protected Bitmap doInBackground(String... objectURL) {
//return ThumbnailUtils.createVideoThumbnail(objectURL[0], Thumbnails.MINI_KIND);
return ThumbnailUtils.extractThumbnail(ThumbnailUtils.createVideoThumbnail(objectURL[0], Thumbnails.MINI_KIND), 100, 100);
}
@Override
protected void onPostExecute(Bitmap result){
img.setImageBitmap(result);
}
}
}
我知道,一个类似的问题已经问过,的 <一个href="http://stackoverflow.com/questions/10750502/displaying-video-thumbnails-in-android-device-from-remote-video-url">Displaying在Android设备上的视频缩略图,从远程视频网址 的,但我已经尝试过这一点,同样的结果。
I know that a similar question has been asked before, Displaying video thumbnails in an Android device from a remote video URL, but I have already tried this and same result.
为什么没有这项工作的设备上,以及如何使其发挥作用?
Why doesn't this work on the device and how make it work?
推荐答案
使用FFmpegMediaMetadataRetriever提取缩略图在所需位置:的 FFmpegMediaMetadataRetriever
Use FFmpegMediaMetadataRetriever to extract a thumbnail at the desired position: FFmpegMediaMetadataRetriever
这篇关于它可以在Android 4.0或以上显示来自URL的视频缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!