本文整理汇总了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;
}
示例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();
}
}
示例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);
}
示例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};
}
示例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;
}
示例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 "";
}
示例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();
}
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}