當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaMetadataRetriever.extractMetadata方法代碼示例

本文整理匯總了Java中android.media.MediaMetadataRetriever.extractMetadata方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaMetadataRetriever.extractMetadata方法的具體用法?Java MediaMetadataRetriever.extractMetadata怎麽用?Java MediaMetadataRetriever.extractMetadata使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.MediaMetadataRetriever的用法示例。


在下文中一共展示了MediaMetadataRetriever.extractMetadata方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getVideoDuration

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
/**
 * 從視頻文件中讀取視頻長度
 */
public static long getVideoDuration(Context context, String videoFile) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    //use one of overloaded setDataSource() functions to set your data source
    String time;
    try {
        retriever.setDataSource(context, Uri.fromFile(new File(videoFile)));
        time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
        int width = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
        int height = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
    } finally {
        try {
            retriever.release();
        } catch (Exception ex) {
            // Ignore failures while cleaning up.
        }
    }

    long timeInMillisec = Long.parseLong(time);

    return timeInMillisec;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:25,代碼來源:ImageGridActivity.java

示例2: getFileMeta

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
/**
 * Used to get information about the written file
 */
private void getFileMeta() {

    if (absolutePath != null) {

        try {

            final MediaMetadataRetriever mmr = new MediaMetadataRetriever();
            mmr.setDataSource(absolutePath);
            final String duration = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
            mmr.release();

            if (DEBUG) {
                MyLog.i(CLS_NAME, "recording duration: " + duration);
            }

        } catch (final RuntimeException e) {
            if (DEBUG) {
                MyLog.w(CLS_NAME, "RuntimeException: completeFileWrite");
                e.printStackTrace();
            }
        }
    }
}
 
開發者ID:brandall76,項目名稱:Saiy-PS,代碼行數:27,代碼來源:FileCreator.java

示例3: parseMP3File

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1)
public static MusicBean parseMP3File(String path) {
    MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    String name = null;
    String singer = null;
    String album = null;
    long duration = 0;


    try {
        mmr.setDataSource(path);
        name = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
        singer = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
        album = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
        duration = Long.valueOf(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
        mmr.release();
    } catch (Exception e) {
        e.printStackTrace();
        return null;

    }
    return new MusicBean(name, singer, album, duration, path);
}
 
開發者ID:piyell,項目名稱:NeteaseCloudMusic,代碼行數:24,代碼來源:MP3Util.java

示例4: formatFileDuration

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
private String formatFileDuration(String path) {
	MediaMetadataRetriever retriever = new MediaMetadataRetriever();
	retriever.setDataSource(path);
	// 取得視頻的長度(單位為毫秒)
	String time = retriever
			.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
	// 取得視頻的長度(單位為秒)
	int totalS = Integer.valueOf(time) / 1000;

	DecimalFormat df = new DecimalFormat("#.00");
	String totalDuration = "";
	if (totalS < 60) {
		totalDuration = df.format((double) totalS) + "秒";
	} else if (totalS < 3600) {
		totalDuration = df.format((double) totalS / 60) + "分";
	} else if (totalS < 3600*24) {
		totalDuration = df.format((double) totalS / 3600) + "時";
	}

	return totalDuration;
}
 
開發者ID:dxjia,項目名稱:GifAssistant,代碼行數:22,代碼來源:VideosInfo.java

示例5: getVideoInfor

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
/** 獲取視頻時長 **/
public static void getVideoInfor(int index) {
	MediaMetadataRetriever mmr = new MediaMetadataRetriever();
	VideoInfo vInfo = videosInfo.get(index);
	mmr.setDataSource(vInfo.videoPath);
	String videoTime = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); // 播放時長單位為毫秒
	String width = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
	String height = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
	String rotation = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);

	if (rotation.equals("90") || rotation.equals("270")) {
		width = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
		height = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
	}
	vInfo.rotation = Integer.parseInt(rotation);
	vInfo.videoTime = Integer.parseInt(videoTime);
	vInfo.totalVideoTime = Integer.parseInt(videoTime);
	vInfo.endVideoTime = Integer.parseInt(videoTime);
	
	
	vInfo.width = Integer.parseInt(width);
	vInfo.height = Integer.parseInt(height);
}
 
開發者ID:smartbeng,項目名稱:PaoMovie,代碼行數:24,代碼來源:StaticMethod.java

示例6: getMetaData

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
@TargetApi(10)
private static SparseArray<String> getMetaData (final String videoFile, JSONArray requestedMetaDatas) throws JSONException, IOException, RuntimeException {
	File f = new File(videoFile);
	SparseArray<String> returnArray = new SparseArray<>();

	if (f.exists()) {
		MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
		metadataRetriever.setDataSource(f.getAbsolutePath());

		for (int i = 0; i < requestedMetaDatas.length(); i++) {
			int metaDataKey = requestedMetaDatas.getInt(i);
			String metaDataValue = metadataRetriever.extractMetadata(metaDataKey);

			if (metaDataValue != null) {
				returnArray.put(metaDataKey, metaDataValue);
			}
		}
	}
	else {
		throw new IOException("File: " + f.getAbsolutePath() + " doesn't exist");
	}

	return returnArray;
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:25,代碼來源:Cache.java

示例7: updateMovieInfo

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
@Override
protected void updateMovieInfo(final MediaMetadataRetriever metadata) {
	super.updateMovieInfo(metadata);

	mVideoWidth = mVideoHeight = mRotation = 0;
	String value = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
	if (!TextUtils.isEmpty(value)) {
		mVideoWidth = Integer.parseInt(value);
	}
	value = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
	if (!TextUtils.isEmpty(value)) {
		mVideoHeight = Integer.parseInt(value);
	}
	value = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
	if (!TextUtils.isEmpty(value)) {
		mRotation = Integer.parseInt(value);
	}
}
 
開發者ID:saki4510t,項目名稱:libcommon,代碼行數:19,代碼來源:MediaVideoDecoder.java

示例8: extractBitmap

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
public static Bitmap extractBitmap(String videoPath, int second) {
	if (TextUtils.isEmpty(videoPath)) {
		logd("extractBitmap empty video path");
		return null;
	}

	MediaMetadataRetriever retriever = new MediaMetadataRetriever();
	retriever.setDataSource(videoPath);
	// 取得視頻的長度(單位為毫秒)
	String time = retriever
			.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
	// 取得視頻的長度(單位為秒)
	int total = Integer.valueOf(time) / 1000;

	if (second < 0 || second > total) {
		loge("unavalible second(" + second + "), total(" + total + ")");
		return null;
	}

	Bitmap bitmap = retriever.getFrameAtTime(second * 1000 * 1000,
			MediaMetadataRetriever.OPTION_CLOSEST_SYNC);

	return bitmap;
}
 
開發者ID:dxjia,項目名稱:GifAssistant,代碼行數:25,代碼來源:ExtractPicturesWorker.java

示例9: verifyLocationInFile

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
private void verifyLocationInFile(String fileName) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(fileName);
    String location = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_LOCATION);
    assertNotNull("No location information found in file " + fileName, location);
    // parsing String location and recover the location inforamtion in floats
    // Make sure the tolerance is very small - due to rounding errors.
    // Get the position of the -/+ sign in location String, which indicates
    // the beginning of the longtitude.
    int index = location.lastIndexOf('-');
    if (index == -1) {
        index = location.lastIndexOf('+');
    }
    assertTrue("+ or - is not found", index != -1);
    assertTrue("+ or - is only found at the beginning", index != 0);
    float latitude = Float.parseFloat(location.substring(0, index - 1));
    float longitude = Float.parseFloat(location.substring(index));
    assertTrue("Incorrect latitude: " + latitude,
            Math.abs(latitude - LATITUDE) <= TOLERANCE);
    assertTrue("Incorrect longitude: " + longitude,
            Math.abs(longitude - LONGITUDE) <= TOLERANCE);
    retriever.release();
}
 
開發者ID:binkery,項目名稱:allinone,代碼行數:24,代碼來源:MediaMuxerTest.java

示例10: loadRotationMetdata

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
static void loadRotationMetdata(final LocalData data) {
    final String path = data.getPath();
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(path);
        String rotation = retriever.extractMetadata(
            MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
        data.getMetadata().putString(ROTATION_KEY, rotation);

        String val = retriever.extractMetadata(
                MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
        int width = Integer.parseInt(val);

        data.getMetadata().putInt(WIDTH_KEY, width);

        val = retriever.extractMetadata(
                MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
        int height = Integer.parseInt(val);

        data.getMetadata().putInt(HEIGHT_KEY, height);
    } catch (RuntimeException ex) {
        // setDataSource() can cause RuntimeException beyond
        // IllegalArgumentException. e.g: data contain *.avi file.
        Log.e(TAG, "MediaMetdataRetriever.setDataSource() fail", ex);
    }
}
 
開發者ID:jameliu,項目名稱:Camera2,代碼行數:27,代碼來源:VideoRotationMetadataLoader.java

示例11: getRotation

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
public int getRotation()
{
  MediaMetadataRetriever retriever = new MediaMetadataRetriever();
  if (this.path != null)
    retriever.setDataSource(this.path);
  else if (this.fileDescriptor != null)
    retriever.setDataSource(this.fileDescriptor);
  else if (this.uri != null)
    retriever.setDataSource(this.context, android.net.Uri.parse(this.uri.getString()));
  else {
    throw new IllegalStateException("File not set");
  }
  String rotation = retriever.extractMetadata(24);
  retriever.release();
  return Integer.parseInt(rotation);
}
 
開發者ID:jiangerji,項目名稱:android-screen-recorder,代碼行數:17,代碼來源:MediaExtractorPlugin.java

示例12: getBasicMetaData

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
/**
 * Creates an array of basic information about an audio file obtained through the
 * MediaMetaDataRetriever. If a file does not provide MetaData, the filename will be used as
 * the title.
 * The array contains information as follows:
 * [0] METADATA_KEY_ARTIST
 * [1] METADATA_KEY_TITLE
 * [2] METADATA_KEY_DURATION
 *
 * @param filePath path to the file
 * @return String array with metadata.
 */
public static String[] getBasicMetaData(String filePath)
{
	Log.d(DEBUG_TAG, "Reading audio metadata for " + filePath);
	MediaMetadataRetriever mmr = new MediaMetadataRetriever();
	mmr.setDataSource(filePath);
	String[] metaData = new String[3];
	metaData[0] =
			mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
	metaData[1] =
			mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
	metaData[2] =
			mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
	if (metaData[0] == null)
	{
		metaData[0] = "-";
	}
	if (metaData[1] == null)
	{
		String[] pathSep = filePath.split("/");
		metaData[1] = pathSep[pathSep.length - 1];
	}
	return metaData;
}
 
開發者ID:AlphaBetaPeter,項目名稱:alarming,代碼行數:36,代碼來源:MediaUtil.java

示例13: getMetaData

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
public static MetaData getMetaData(String localPath) {
    int height = 0;
    int width = 0;
    int durationSec = 0;

    MediaMetadataRetriever mmr = getMediaMetadataRetriever(localPath);
    String heightStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
    String widthStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
    String durationStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);

    if (!TextUtils.isEmpty(heightStr)) {
        height = Integer.parseInt(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
    }
    if (!TextUtils.isEmpty(widthStr)) {
        width = Integer.parseInt(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
    }
    if (!TextUtils.isEmpty(durationStr)) {
        int durationMs = Integer.parseInt(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
        durationSec = (int) TimeUnit.MILLISECONDS.toSeconds(durationMs);
    }

    return new MetaData(height, width, durationSec);
}
 
開發者ID:QuickBlox,項目名稱:q-municate-android,代碼行數:24,代碼來源:MediaUtils.java

示例14: getOutputVideoBitRate

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
private int getOutputVideoBitRate() {
    int inputBitRate = mOutputVideoBitRate;

    if (mInputVideoComponent.getTrackFormat().containsKey(MediaFormat.KEY_BIT_RATE)) {
        inputBitRate = mInputVideoComponent.getTrackFormat().getInteger(MediaFormat.KEY_BIT_RATE);
    } else {
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        retriever.setDataSource(mContext, mSrcUri);

        String bitrate = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);

        if (bitrate != null) {
            inputBitRate = Integer.parseInt(bitrate);
        }
    }

    if (DeviceUtils.deviceisOnBlacklist()) {
        return mOutputVideoBitRate;
    } else {
        return Math.min(inputBitRate, mOutputVideoBitRate);
    }
}
 
開發者ID:groupme,項目名稱:android-video-kit,代碼行數:23,代碼來源:VideoTranscoder.java

示例15: initMediaDuration

import android.media.MediaMetadataRetriever; //導入方法依賴的package包/類
protected void initMediaDuration() throws MmsException {
    if (mUri == null) {
        throw new IllegalArgumentException("Uri may not be null.");
    }

    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    int duration = 0;
    if(!isVcard()){
    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();
    }
    }
}
 
開發者ID:CommonQ,項目名稱:sms_DualCard,代碼行數:24,代碼來源:MediaModel.java


注:本文中的android.media.MediaMetadataRetriever.extractMetadata方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。