use of android.media.MediaMetadataRetriever in project react-native-android-video-editor by RZulfikri.
the class VideoSurfaceView method setSource.
public void setSource(String uri) {
videoUri = uri;
try {
mMediaPlayer.setDataSource(uri);
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(uri);
videoHeight = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
videoWidth = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
rotation = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
if (videoWidth > 0 && videoHeight > 0) {
setDimension();
}
videoDuration = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
WritableMap event = Arguments.createMap();
event.putInt(Events.VIDEO_DURATION, videoDuration);
eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_VIDEO_DURATION.toString(), event);
retriever.release();
retriever = null;
} catch (IOException e) {
e.printStackTrace();
}
}
use of android.media.MediaMetadataRetriever in project AntennaPod by AntennaPod.
the class ExternalMedia method loadMetadata.
@Override
public void loadMetadata() throws PlayableException {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
try {
mmr.setDataSource(source);
} catch (IllegalArgumentException e) {
e.printStackTrace();
throw new PlayableException("IllegalArgumentException when setting up MediaMetadataReceiver");
} catch (RuntimeException e) {
// http://code.google.com/p/android/issues/detail?id=39770
e.printStackTrace();
throw new PlayableException("RuntimeException when setting up MediaMetadataRetriever");
}
episodeTitle = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
feedTitle = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
try {
duration = Integer.parseInt(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
} catch (NumberFormatException e) {
e.printStackTrace();
throw new PlayableException("NumberFormatException when reading duration of media file");
}
ChapterUtils.loadChaptersFromFileUrl(this);
}
use of android.media.MediaMetadataRetriever in project AntennaPod by AntennaPod.
the class AudioCoverFetcher method loadData.
@Override
public InputStream loadData(Priority priority) throws Exception {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(path);
byte[] picture = retriever.getEmbeddedPicture();
if (picture != null) {
return new ByteArrayInputStream(picture);
}
} finally {
retriever.release();
}
throw new IOException("Loading embedded cover did not work");
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by DirtyUnicorns.
the class MediaDecoder method retrieveDefaultRotation.
@TargetApi(17)
private void retrieveDefaultRotation() {
MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
metadataRetriever.setDataSource(mContext, mUri);
String rotationString = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
mDefaultRotation = rotationString == null ? 0 : Integer.parseInt(rotationString);
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by DirtyUnicorns.
the class CodecTest method getThumbnail.
//Test for mediaMeta Data Thumbnail
public static boolean getThumbnail(String filePath, String goldenPath) {
Log.v(TAG, "getThumbnail - " + filePath);
int goldenHeight = 0;
int goldenWidth = 0;
int outputWidth = 0;
int outputHeight = 0;
//This test is only for the short media file
try {
BitmapFactory mBitmapFactory = new BitmapFactory();
MediaMetadataRetriever mMediaMetadataRetriever = new MediaMetadataRetriever();
try {
mMediaMetadataRetriever.setDataSource(filePath);
} catch (Exception e) {
e.printStackTrace();
return false;
}
Bitmap outThumbnail = mMediaMetadataRetriever.getFrameAtTime(-1);
//Verify the thumbnail
Bitmap goldenBitmap = mBitmapFactory.decodeFile(goldenPath);
outputWidth = outThumbnail.getWidth();
outputHeight = outThumbnail.getHeight();
goldenHeight = goldenBitmap.getHeight();
goldenWidth = goldenBitmap.getWidth();
//check the image dimension
if ((outputWidth != goldenWidth) || (outputHeight != goldenHeight))
return false;
// Check half line of pixel
int x = goldenHeight / 2;
for (int j = 1; j < goldenWidth / 2; j++) {
if (goldenBitmap.getPixel(x, j) != outThumbnail.getPixel(x, j)) {
Log.v(TAG, "pixel = " + goldenBitmap.getPixel(x, j));
return false;
}
}
} catch (Exception e) {
Log.v(TAG, e.toString());
return false;
}
return true;
}
Aggregations