以下两者在模拟器(2.3.3)上都可以正常工作,但在真实设备(Nexus S和 4.1.2)上没有显示缩略图的图像。我还将尝试在Android 4 Emulator
. 如果我为 设置默认值android:src
,ImageView
则不再显示它。这让我觉得它被替换了,但它ImageView
是空的。
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);
}
}
}
我知道之前有人问过类似的问题,Displaying video thumbnails in an Android device from a remote video URL,但我已经尝试过这个和相同的结果。
为什么这在设备上不起作用以及如何使它起作用?