4

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;
        }
serenskye
  • 3,467
  • 5
  • 35
  • 51
  • Did you manage to resolve this issue? I have the exact same issue and can't find a solution. – ClassA Jan 28 '18 at 10:21

1 Answers1

1

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();
William Seemann
  • 3,440
  • 10
  • 44
  • 78