Android MediaMetadataRetriever - top ranked examples from Open Source projects

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

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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:extractMetadata, release, setDataSource
    protected void initMediaDuration() throws MmsException { 
        if (mUri == null) {
            throw new IllegalArgumentException("Uri may not be null.");
        } 
 
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        int duration = 0;
        try { 
            retriever.setDataSource(mContext, mUri);
            String dur = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
            if (dur != null) {
                duration = Integer.parseInt(dur);
            } 
            mDuration = duration;
        } catch (Exception ex) {
            Log.e(TAG, "MediaMetadataRetriever failed to get duration for " + mUri.getPath(), ex);
            throw new MmsException(ex);
        } finally { 
            retriever.release();
        } 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:extractMetadata, setDataSource
                default: 
                    return new MediaMetadata(durationInMilliseconds, width, height, success);
            } 
        } 
 
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try { 
            Uri uri = Uri.parse(url);
            String scheme = uri.getScheme();
            if (scheme == null || scheme.equals("file")) {
                File file = new File(uri.getPath());
                String path = file.getAbsolutePath();
                if (file.exists() && (path.startsWith("/mnt/sdcard/") ||
                        path.startsWith("/sdcard/") ||
                        path.startsWith(PathUtils.getExternalStorageDirectory()))) {
                    retriever.setDataSource(path);
                } else { 
                    Log.e(TAG, "Unable to read file: " + url);
                    return new MediaMetadata(durationInMilliseconds, width, height, success);
                } 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setDataSource
	/** 
	 * Create an MediaMetadataRetriever attached to the file at the given path. 
	 */ 
	public CompatMetadata(String path)
	{ 
		MediaMetadataRetriever data = new MediaMetadataRetriever();
		data.setDataSource(path);
		mData = data;
	} 
 
	/** 
	 * Call {@link MediaMetadataRetriever#extractMetadata(int)}. 
	 */ 
	public String extractMetadata(int keyCode)
	{ 
		return mData.extractMetadata(keyCode);
	} 
 
	/** 
	 * Call {@link MediaMetadataRetriever#release()}. 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:extractMetadata, release, setDataSource
		    } while (cursor.moveToNext());
		} 
	} 
	 
	public static void getMediaInfo(String path, MediaBean bean){
		MediaMetadataRetriever retriever = new MediaMetadataRetriever();
		retriever.setDataSource(path);
		 
		File file=new File(path);
		if(file!=null){
			Log.i("TAG", "地址可用!");
			long length=file.length();
			bean.setSize(length/(1024*1024));
		} 
		 
		if(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE)!=null){
			bean.setTitle(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE));
		}else{ 
			String title = path.substring(path.lastIndexOf(File.separator)+1);
			bean.setTitle(title);

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android MediaMetadataRetriever Questions & Answers:

See Code Examples for Android MediaMetadataRetriever Methods: