MediaMetadataRetriever getFrameAtTime - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for MediaMetadataRetriever getFrameAtTime method.

This code example shows how to use the following methods:getFrameAtTime, release, setDataSource
        mThumbnailView.setImageBitmap(thumbnail);
    } 
 
    public static Bitmap createVideoThumbnail(Context context, Uri uri) {
        Bitmap bitmap = null;
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try { 
            retriever.setDataSource(context, uri);
            bitmap = retriever.getFrameAtTime(-1);
        } catch (RuntimeException ex) {
            // Assume this is a corrupt video file. 
        } finally { 
            try { 
                retriever.release();
            } catch (RuntimeException ex) {
                // Ignore failures while cleaning up. 
            } 
        } 
        return bitmap;
    } 
9
CodeRank
This code example shows how to use the following methods:getFrameAtTime, release, setDataSource
    } 
 
    private static Bitmap createVideoThumbnailBitmap(String filePath, FileDescriptor fd,
            int targetWidth) {
        Bitmap bitmap = null;
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try { 
            if (filePath != null) {
                retriever.setDataSource(filePath);
            } else { 
                retriever.setDataSource(fd);
            } 
            bitmap = retriever.getFrameAtTime(-1);
        } catch (IllegalArgumentException ex) {
            // Assume this is a corrupt video file 
        } catch (RuntimeException ex) {
            // Assume this is a corrupt video file. 
        } finally { 
            try { 
                retriever.release();

7
CodeRank
This code example shows how to use the following methods:getFrameAtTime, release, setDataSource
package org.ffmpeg.android; 
 
import android.graphics.Bitmap; 
import android.media.MediaMetadataRetriever; 
import android.util.Log; 
 
public class MediaUtils { 
 
	public static Bitmap getVideoFrame(String videoPath,long frameTime) {
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
         
        try { 
            retriever.setDataSource(videoPath);      
            return retriever.getFrameAtTime(frameTime, MediaMetadataRetriever.OPTION_CLOSEST);
        } catch (IllegalArgumentException ex) {
            Log.w("FFMPEG.MediaUtils", "illegal argument exception");
             
        } catch (RuntimeException ex) {
        	Log.w("FFMPEG.MediaUtils", "error getting video frame");
                                } finally { 

7
CodeRank
This code example shows how to use the following methods:getFrameAtTime, release, setDataSource
        mThumbnailView.setImageBitmap(thumbnail);
    } 
 
    public static Bitmap createVideoThumbnail(Context context, Uri uri) {
        Bitmap bitmap = null;
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try { 
            retriever.setDataSource(context, uri);
            bitmap = retriever.getFrameAtTime(-1);
        } catch (RuntimeException ex) {
            // Assume this is a corrupt video file. 
        } finally { 
            try { 
                retriever.release();
            } catch (RuntimeException ex) {
                // Ignore failures while cleaning up. 
            } 
        } 
        return bitmap;
    } 
6
CodeRank
This code example shows how to use the following methods:getFrameAtTime, release, setDataSource
        return createVideoThumbnail(filePath, null, targetWidth);
    } 
 
    private static Bitmap createVideoThumbnail(String filePath, FileDescriptor fd, int targetWidth) {
        Bitmap bitmap = null;
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try { 
            if (filePath != null) {
                retriever.setDataSource(filePath);
            } else { 
                retriever.setDataSource(fd);
            } 
            bitmap = retriever.getFrameAtTime(-1);
        } catch (IllegalArgumentException ex) {
            // Assume this is a corrupt video file 
        } catch (RuntimeException ex) {
            // Assume this is a corrupt video file. 
        } finally { 
            try { 
                retriever.release();

6
CodeRank
This code example shows how to use the following methods:getFrameAtTime, release, setDataSource
			throw new RuntimeException(exception);
		} 
	} 
 
	private static Bitmap getVideoFrame(Context context, Uri uri, long time) {
		MediaMetadataRetriever retriever = new MediaMetadataRetriever();
 
		try { 
			retriever.setDataSource(context, uri);
			return retriever.getFrameAtTime(time);
		} catch (IllegalArgumentException ex) {
			ex.printStackTrace();
		} catch (RuntimeException ex) {
			ex.printStackTrace();
		} finally { 
			try { 
				retriever.release();
			} catch (RuntimeException ex) {
			} 
		} 

6
CodeRank
This code example shows how to use the following methods:getFrameAtTime, release, setDataSource
            return android.media.ThumbnailUtils.createVideoThumbnail(filePath, kind);
        } 
         
        // MediaMetadataRetriever is not available for Android version less than 10 
        // but we need to use it in order to get first frame of the video for thumbnail. 
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
         
        try { 
            retriever.setDataSource(filePath);
            bitmap = retriever.getFrameAtTime(0);
        } catch (IllegalArgumentException ex) {
            // Assume this is a corrupt video file 
        } catch (RuntimeException ex) {
            // Assume this is a corrupt video file. 
        } finally { 
            try { 
                retriever.release();
            } catch (RuntimeException ex) {
                // Ignore failures while cleaning up. 
                Log.w("ThumbnailUtils", "MediaMetadataRetriever failed with exception: " + ex);

6
CodeRank
This code example shows how to use the following methods:getFrameAtTime, release, setDataSource
        } 
    } 
 
    public static Bitmap createVideoThumbnail(Context context, Uri uri) {
        Bitmap bitmap = null;
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try { 
            retriever.setDataSource(context, uri);
            bitmap = retriever.getFrameAtTime(-1);
        } catch (RuntimeException ex) {
            // Assume this is a corrupt video file. 
        } finally { 
            try { 
                retriever.release();
            } catch (RuntimeException ex) {
                // Ignore failures while cleaning up. 
            } 
        } 
        return bitmap;
    } 
5
CodeRank
This code example shows how to use the following methods:getFrameAtTime, release, setDataSource
	public Bitmap createVideoThumbnail(String path , long position) {
		System.out.println("CREATE THUM£££££");
		System.out.println("MEDIA RETRIEVER "+path);
        System.out.println("POSITION "+position);
	    Bitmap bitmap = null;
	    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
	    try { 
	         System.out.println("MEDIA RETRIEVER "+path);
	         System.out.println("POSITION "+position);
	        retriever.setDataSource(path);
	        bitmap = retriever.getFrameAtTime(position,MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
	        System.out.println("PRINT BITMAP "+bitmap);
	    }catch(IllegalArgumentException e){
	    	e.printStackTrace();
	    } 
	    catch (RuntimeException ex) {
	        // Assume this is a corrupt video file. 
	    }catch (Exception e) {
			// TODO: handle exception 
		} finally { 

6
CodeRank
This code example shows how to use the following methods:getFrameAtTime, release, setDataSource
        } 
    } 
 
    public static Bitmap createVideoThumbnail(Context context, Uri uri) {
        Bitmap bitmap = null;
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try { 
            retriever.setDataSource(context, uri);
            bitmap = retriever.getFrameAtTime(-1);
        } catch (RuntimeException ex) {
            // Assume this is a corrupt video file. 
        } finally { 
            try { 
                retriever.release();
            } catch (RuntimeException ex) {
                // Ignore failures while cleaning up. 
            } 
        } 
        return bitmap;
    } 
5
CodeRank

Related MediaMetadataRetriever getFrameAtTime Questions & Answers:

getFrameAtTime Method Overview
Call this method after setDataSource().
See Code Examples for other Android MediaMetadataRetriever Methods: