Code example for MediaMetadataRetriever

Methods: extractMetadata, release, setDataSource

0
    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();
        } 
    } 
 
    private void initMediaSize() throws MmsException { 
        ContentResolver cr = mContext.getContentResolver();