use of android.media.MediaMetadataRetriever in project Telecine by JakeWharton.
the class RecordingSession method showNotification.
private void showNotification(final Uri uri, Bitmap bitmap) {
Intent viewIntent = new Intent(ACTION_VIEW, uri);
PendingIntent pendingViewIntent = PendingIntent.getActivity(context, 0, viewIntent, FLAG_CANCEL_CURRENT);
Intent shareIntent = new Intent(ACTION_SEND);
shareIntent.setType(MIME_TYPE);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent = Intent.createChooser(shareIntent, null);
PendingIntent pendingShareIntent = PendingIntent.getActivity(context, 0, shareIntent, FLAG_CANCEL_CURRENT);
Intent deleteIntent = new Intent(context, DeleteRecordingBroadcastReceiver.class);
deleteIntent.setData(uri);
PendingIntent pendingDeleteIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, FLAG_CANCEL_CURRENT);
CharSequence title = context.getText(R.string.notification_captured_title);
CharSequence subtitle = context.getText(R.string.notification_captured_subtitle);
CharSequence share = context.getText(R.string.notification_captured_share);
CharSequence delete = context.getText(R.string.notification_captured_delete);
Notification.Builder builder = //
new Notification.Builder(context).setContentTitle(title).setContentText(subtitle).setWhen(System.currentTimeMillis()).setShowWhen(true).setSmallIcon(R.drawable.ic_videocam_white_24dp).setColor(context.getResources().getColor(R.color.primary_normal)).setContentIntent(pendingViewIntent).setAutoCancel(true).addAction(R.drawable.ic_share_white_24dp, share, pendingShareIntent).addAction(R.drawable.ic_delete_white_24dp, delete, pendingDeleteIntent);
if (bitmap != null) {
builder.setLargeIcon(createSquareBitmap(bitmap)).setStyle(//
new Notification.BigPictureStyle().setBigContentTitle(//
title).setSummaryText(//
subtitle).bigPicture(bitmap));
}
notificationManager.notify(NOTIFICATION_ID, builder.build());
if (bitmap != null) {
listener.onEnd();
return;
}
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(@NonNull Void... none) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(context, uri);
return retriever.getFrameAtTime();
}
@Override
protected void onPostExecute(@Nullable Bitmap bitmap) {
if (bitmap != null && !notificationDismissed()) {
showNotification(uri, bitmap);
} else {
listener.onEnd();
}
}
private boolean notificationDismissed() {
return SDK_INT >= M && notificationManager.getActiveNotifications().length == 0;
}
}.execute();
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by ParanoidAndroid.
the class MediaMetadataTest method validateMetatData.
private static void validateMetatData(int fileIndex, String[][] meta_data_file) {
Log.v(TAG, "filePath = " + meta_data_file[fileIndex][0]);
if ((meta_data_file[fileIndex][0].endsWith("wma") && !MediaProfileReader.getWMAEnable()) || (meta_data_file[fileIndex][0].endsWith("wmv") && !MediaProfileReader.getWMVEnable())) {
return;
}
String value = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(meta_data_file[fileIndex][0]);
} catch (Exception e) {
Log.v(TAG, "Failed: " + meta_data_file[fileIndex][0] + " " + e.toString());
//Set the test case failure whenever it failed to setDataSource
assertTrue("Failed to setDataSource ", false);
}
//METADATA_KEY_CD_TRACK_NUMBER should return the TCRK value
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER);
Log.v(TAG, "CD_TRACK_NUMBER : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.CD_TRACK.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
Log.v(TAG, "Album : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.ALBUM.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
Log.v(TAG, "Artist : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.ARTIST.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_AUTHOR);
Log.v(TAG, "Author : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.AUTHOR.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER);
Log.v(TAG, "Composer : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.COMPOSER.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE);
Log.v(TAG, "Date : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.DATE.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
Log.v(TAG, "Genre : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.GENRE.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
Log.v(TAG, "Title : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.TITLE.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
Log.v(TAG, "Year : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.YEAR.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
Log.v(TAG, "Expected = " + meta_data_file[fileIndex][meta.DURATION.ordinal()] + "reult = " + value);
// Only require that the returned duration is within 100ms of the expected
// one as PV and stagefright differ slightly in their implementation.
assertTrue(TAG, Math.abs(Integer.parseInt(meta_data_file[fileIndex][meta.DURATION.ordinal()]) - Integer.parseInt(value)) < 100);
//METADATA_KEY_NUM_TRACKS should return the total number of tracks in the media
//include the video and audio
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS);
Log.v(TAG, "Track : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.NUM_TRACKS.ordinal()], value);
value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_WRITER);
Log.v(TAG, "Writer : " + value);
assertEquals(TAG, meta_data_file[fileIndex][meta.WRITER.ordinal()], value);
retriever.release();
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by ParanoidAndroid.
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;
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by ParanoidAndroid.
the class MediaMetadataRetrieverTest method testBasicAbnormalMethodCallSequence.
// If setDataSource() has not been called, both getFrameAtTime() and extractMetadata() must
// return null.
@MediumTest
public static void testBasicAbnormalMethodCallSequence() {
boolean hasFailed = false;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
if (retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM) != null) {
Log.e(TAG, "No album metadata expected, but is available");
hasFailed = true;
}
if (retriever.getFrameAtTime(-1) != null) {
Log.e(TAG, "No frame expected, but is available");
hasFailed = true;
}
assertTrue(!hasFailed);
}
use of android.media.MediaMetadataRetriever in project android_frameworks_base by ParanoidAndroid.
the class MediaMetadataRetrieverTest method testBasicNormalMethodCallSequence.
// If the specified call order and valid media file is used, no exception
// should be thrown.
@MediumTest
public static void testBasicNormalMethodCallSequence() throws Exception {
boolean hasFailed = false;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(MediaNames.TEST_PATH_1);
Bitmap bitmap = retriever.getFrameAtTime(-1);
assertTrue(bitmap != null);
try {
java.io.OutputStream stream = new FileOutputStream("/sdcard/thumbnailout.jpg");
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream);
stream.close();
} catch (Exception e) {
throw new Exception("Fails to convert the bitmap to a JPEG file for " + MediaNames.TEST_PATH_1, e);
}
extractAllSupportedMetadataValues(retriever);
} catch (Exception e) {
Log.e(TAG, "Fails to setDataSource for " + MediaNames.TEST_PATH_1, e);
hasFailed = true;
}
retriever.release();
assertTrue(!hasFailed);
}
Aggregations