12

以下两者在模拟器(2.3.3)上都可以正常工作,但在真实设备(Nexus S和 4.1.2)上没有显示缩略图的图像。我还将尝试在Android 4 Emulator. 如果我为 设置默认值android:srcImageView则不再显示它。这让我觉得它被替换了,但它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,但我已经尝试过这个和相同的结果。

为什么这在设备上不起作用以及如何使它起作用?

4

3 回答 3

2

Use FFmpegMediaMetadataRetriever to extract a thumbnail at the desired position: FFmpegMediaMetadataRetriever

于 2014-05-07T16:23:17.623 回答
0

This is not possible on Android and Java and as far as I know any other language without downloading the entire video (correct me if I'm wrong). It is with good reason that YouTube and any other large video service provide a simple API for getting a video thumb. So if the server where the videos reside doesn't support this kind of API call your in bad luck.

于 2013-03-06T08:24:27.760 回答
0

Faced the same problem on 2.3 when tried to make thumbnail from file which was located in the cache folder. Setting permission flags solved the problem:

videoFile.setReadable(true, false);
于 2013-11-28T14:07:39.627 回答