MediaMetadataRetriever always returns null when trying to retrieve a frame

2.7k Views Asked by At

I'm trying to get the first frame of a Streaming video via the URL. getFrameAtTime always seems to return null with no Exception.

        @Override
        protected Bitmap doInBackground(String... strings) {
            String url = strings[0];
            MediaMetadataRetriever retriever = new MediaMetadataRetriever(); //Is actually available in Api levels < 10 all the way to 5
            try {
                retriever.setDataSource(url, new HashMap<String, String>());
                return retriever.getFrameAtTime(1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
            } catch (IllegalArgumentException ex) {
                ex.printStackTrace();
                Log.e(TAG, "problem retrieving frame " + ex);
            } catch (RuntimeException ex) {
                ex.printStackTrace();
                Log.e(TAG, "problem retrieving frame " + ex);
            } finally {
                try {
                    retriever.release();
                } catch (RuntimeException ex) {
                    Log.e(TAG, "problem retrieving frame " + ex);
                }
            }
            return null;
        }
1

There are 1 best solutions below

2
On

Have you tried FFmpegMediaMetadataRetriever?:

FFmpegMediaMetadataRetriever retriever = new FFmpegMediaMetadataRetriever();
retriever.setDataSource(url, new HashMap<String, String>());
Bitmap b = retriever.getFrameAtTime(1000000, FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC); // get frame at one second
retriever.release();