当前位置: 首页>>代码示例>>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;未经允许,请勿转载。