当前位置: 首页>>代码示例>>Java>>正文


Java MediaMetadataRetriever.getFrameAtTime方法代码示例

本文整理汇总了Java中android.media.MediaMetadataRetriever.getFrameAtTime方法的典型用法代码示例。如果您正苦于以下问题:Java MediaMetadataRetriever.getFrameAtTime方法的具体用法?Java MediaMetadataRetriever.getFrameAtTime怎么用?Java MediaMetadataRetriever.getFrameAtTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaMetadataRetriever的用法示例。


在下文中一共展示了MediaMetadataRetriever.getFrameAtTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createBitmaps

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public List<Bitmap> createBitmaps(String path)
   {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(path);
double inc = US_OF_S / fps;

for (double i = begin * US_OF_S; i < end * US_OF_S; i += inc)
{
    Bitmap frame = mmr.getFrameAtTime((long) i, MediaMetadataRetriever.OPTION_CLOSEST);
    if (frame != null)
    {
	bitmaps.add(scale(frame));
    }
}

return bitmaps;
   }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:18,代码来源:BitmapExtractor.java

示例2: getAlbumArtFromMP3File

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.GINGERBREAD_MR1)
public static Bitmap getAlbumArtFromMP3File(String path) {
    MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    try {
        mmr.setDataSource(path);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return null;
    }
    byte[] bytes = mmr.getEmbeddedPicture();
    if (null != bytes) {
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    } else {
        return mmr.getFrameAtTime();
    }
}
 
开发者ID:piyell,项目名称:NeteaseCloudMusic,代码行数:17,代码来源:MP3Util.java

示例3: generateVideoThumbnail

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
private ThumbnailData generateVideoThumbnail(MasterSecret masterSecret, AttachmentId attachmentId) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    Log.w(TAG, "Video thumbnails not supported...");
    return null;
  }

  File mediaFile = getAttachmentDataFile(attachmentId, DATA);

  if (mediaFile == null) {
    Log.w(TAG, "No data file found for video thumbnail...");
    return null;
  }

  EncryptedMediaDataSource dataSource = new EncryptedMediaDataSource(masterSecret, mediaFile);
  MediaMetadataRetriever   retriever  = new MediaMetadataRetriever();
  retriever.setDataSource(dataSource);

  Bitmap bitmap = retriever.getFrameAtTime(1000);

  Log.w(TAG, "Generated video thumbnail...");
  return new ThumbnailData(bitmap);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:23,代码来源:AttachmentDatabase.java

示例4: getVideoDimensions

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public static int[] getVideoDimensions(String path) throws FileNotFoundException {
    File file = new File(path);
    if (!file.exists()) {
        throw new FileNotFoundException();
    }

    MediaMetadataRetriever retriever = new MediaMetadataRetriever();

    try {
        retriever.setDataSource(path);
        Bitmap bitmap = retriever.getFrameAtTime();

        int[] dimensions = new int[2];

        if (bitmap != null) {
            dimensions[0] = bitmap.getWidth() > 0 ? bitmap.getWidth() : 1;
            dimensions[1] = bitmap.getHeight() > 0 ? bitmap.getHeight() : 1;
        }
        return dimensions;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return new int[]{1, 1};
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:26,代码来源:Util.java

示例5: getBitmapFromVideoFile

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
private Bitmap getBitmapFromVideoFile(String path) {
    try {
        if (path == null) {
            return null;
        }

        MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
        metadataRetriever.setDataSource(path);
        final WeakReference<Bitmap> weakBmp = new WeakReference<>(metadataRetriever.getFrameAtTime());
        return weakBmp.get();
    } catch (Exception e) {
        Log.w(LOG_TAG, "Error getting bitmap from the video", e);
    }

    return null;
}
 
开发者ID:MimiReader,项目名称:mimi-reader,代码行数:17,代码来源:GalleryWebmFragment.java

示例6: getVideoCover

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public static String getVideoCover(String videoPath, String coverName) {
  coverName = TextUtils.isEmpty(coverName) ? COVER_NAME : coverName;
  String parentPath = new File(videoPath).getParent();
  String coverPath = parentPath.endsWith(File.separator) ? parentPath
      + coverName : parentPath + File.separator + coverName;
  if (new File(coverPath).isFile()) {
    return coverPath;
  }
  MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
  mediaMetadataRetriever.setDataSource(videoPath);
  Bitmap bitmap = mediaMetadataRetriever.getFrameAtTime(1);
  mediaMetadataRetriever.release();
  if (bitmap != null) {
    return FileUtils.saveBitmapToFile(bitmap, new File(videoPath).getParent(), coverName,
        FILTER_COVER_NAME.equals(coverName) ? 10 : 100);
  }
  return "";
}
 
开发者ID:XueyanLiu,项目名称:miku,代码行数:19,代码来源:VideoUtils.java

示例7: loadData

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
public InputStream loadData(Priority priority) throws Exception {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        Log.d("VideoThumbnailFetcher", "model.path= " + model.path);
        retriever.setDataSource(model.path, new HashMap<String, String>());
        Bitmap bitmap = retriever.getFrameAtTime();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] picture = stream.toByteArray();
        if (picture != null) {
            return new ByteArrayInputStream(picture);
        } else {
            return fallback(model.path);
        }
    } finally {
        retriever.release();
    }
}
 
开发者ID:QuickBlox,项目名称:ChatMessagesAdapter-android,代码行数:20,代码来源:VideoThumbnailFetcher.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: loadVideoThumbnail

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
 * Loads the thumbnail of a video.
 *
 * @param path The path to the video file.
 * @return {@code null} if the loading failed.
 */
public static Bitmap loadVideoThumbnail(String path) {
    Bitmap bitmap = null;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(path);
        byte[] data = retriever.getEmbeddedPicture();
        if (data != null) {
            bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
        }
        if (bitmap == null) {
            bitmap = retriever.getFrameAtTime();
        }
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "MediaMetadataRetriever.setDataSource() fail:" + e.getMessage());
    }
    retriever.release();
    return bitmap;
}
 
开发者ID:jameliu,项目名称:Camera2,代码行数:25,代码来源:LocalDataUtil.java

示例10: getBitmap

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public static Bitmap getBitmap(Context context, int id, boolean isImage)
{
	String filename = getDataFilepathForMedia(context.getContentResolver(), id, isImage);
	
	/* ttt_installer:remove_line */Log.d(GTG.TAG,"Loading bitmap for "+filename);
	
	if(filename == null)
		return null;

	if(isImage)
		return new BitmapDrawable(context.getResources(), filename).getBitmap();
	
	MediaMetadataRetriever mmr = new MediaMetadataRetriever();
	mmr.setDataSource(filename);
	return mmr.getFrameAtTime();
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:17,代码来源:Util.java

示例11: sendVideo

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public void sendVideo(Peer peer, String fullFilePath, String fileName) {
    try {
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        retriever.setDataSource(fullFilePath);
        int duration = (int) (Long.parseLong(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)) / 1000L);
        Bitmap img = retriever.getFrameAtTime(0);
        int width = img.getWidth();
        int height = img.getHeight();
        Bitmap smallThumb = ImageHelper.scaleFit(img, 90, 90);
        byte[] smallThumbData = ImageHelper.save(smallThumb);

        FastThumb thumb = new FastThumb(smallThumb.getWidth(), smallThumb.getHeight(), smallThumbData);

        sendVideo(peer, fileName, width, height, duration, thumb, fullFilePath);
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
 
开发者ID:actorapp,项目名称:actor-platform,代码行数:19,代码来源:AndroidMessenger.java

示例12: doInBackground

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
protected Bitmap doInBackground(Void... v) {
    if (isCancelled() || !isUsing()) {
        return null;
    }
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    Bitmap bitmap = null;
    try {
        retriever.setDataSource(mPath);
        byte[] data = retriever.getEmbeddedPicture();
        if (!isCancelled() && isUsing()) {
            if (data != null) {
                bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
            }
            if (bitmap == null) {
                bitmap = retriever.getFrameAtTime();
            }
        }
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "MediaMetadataRetriever.setDataSource() fail:"
                + e.getMessage());
    }
    retriever.release();
    return bitmap;
}
 
开发者ID:asm-products,项目名称:nexus-camera,代码行数:26,代码来源:LocalMediaData.java

示例13: getVideoBmp

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public static Bitmap getVideoBmp(String mFilePath,long timeUs , int option){
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    Bitmap bitmap=null;
    try {
        retriever.setDataSource(mFilePath);
        bitmap = retriever.getFrameAtTime(timeUs);

    } catch (IllegalArgumentException e) {
        e.printStackTrace();

    }
    return bitmap;
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:14,代码来源:MediaMetas.java

示例14: decode

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
public Resource<Bitmap> decode(ParcelFileDescriptor resource, int outWidth, int outHeight,
    Options options) throws IOException {
  long frameTimeMicros = options.get(TARGET_FRAME);
  if (frameTimeMicros < 0 && frameTimeMicros != DEFAULT_FRAME) {
    throw new IllegalArgumentException(
        "Requested frame must be non-negative, or DEFAULT_FRAME, given: " + frameTimeMicros);
  }
  Integer frameOption = options.get(FRAME_OPTION);

  final Bitmap result;
  MediaMetadataRetriever mediaMetadataRetriever = factory.build();
  try {
    mediaMetadataRetriever.setDataSource(resource.getFileDescriptor());
    if (frameTimeMicros == DEFAULT_FRAME) {
      result = mediaMetadataRetriever.getFrameAtTime();
    } else if (frameOption == null) {
      result = mediaMetadataRetriever.getFrameAtTime(frameTimeMicros);
    } else {
      result = mediaMetadataRetriever.getFrameAtTime(frameTimeMicros, frameOption);
    }
  } finally {
    mediaMetadataRetriever.release();
  }
  resource.close();
  return BitmapResource.obtain(result, bitmapPool);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:VideoBitmapDecoder.java

示例15: decode

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
public Resource<Bitmap> decode(ParcelFileDescriptor resource, int outWidth, int outHeight,
    Options options) throws IOException {
  long frameTimeMicros = options.get(TARGET_FRAME);
  if (frameTimeMicros < 0 && frameTimeMicros != DEFAULT_FRAME) {
    throw new IllegalArgumentException(
        "Requested frame must be non-negative, or DEFAULT_FRAME, given: " + frameTimeMicros);
  }
  Integer frameOption = options.get(FRAME_OPTION);

  final Bitmap result;
  MediaMetadataRetriever mediaMetadataRetriever = factory.build();
  try {
    mediaMetadataRetriever.setDataSource(resource.getFileDescriptor());
    if (frameTimeMicros == DEFAULT_FRAME) {
      result = mediaMetadataRetriever.getFrameAtTime();
    } else if (frameOption == null) {
      result = mediaMetadataRetriever.getFrameAtTime(frameTimeMicros);
    } else {
      result = mediaMetadataRetriever.getFrameAtTime(frameTimeMicros, frameOption);
    }
  } catch (RuntimeException e) {
    // MediaMetadataRetriever APIs throw generic runtime exceptions when given invalid data.
    throw new IOException(e);
  } finally {
    mediaMetadataRetriever.release();
  }
  resource.close();
  return BitmapResource.obtain(result, bitmapPool);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:VideoBitmapDecoder.java


注:本文中的android.media.MediaMetadataRetriever.getFrameAtTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。