mirror of https://github.com/M66B/FairEmail.git
Added audio/video duration
This commit is contained in:
parent
6b3bfe0b2e
commit
bd64f70c88
|
@ -28,6 +28,7 @@ import android.graphics.Color;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.pdf.PdfRenderer;
|
import android.graphics.pdf.PdfRenderer;
|
||||||
|
import android.media.MediaMetadataRetriever;
|
||||||
import android.media.ThumbnailUtils;
|
import android.media.ThumbnailUtils;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
@ -110,11 +111,6 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
|
||||||
tvProperties.setVisibility(View.GONE);
|
tvProperties.setVisibility(View.GONE);
|
||||||
|
|
||||||
if (attachment.available) {
|
if (attachment.available) {
|
||||||
if (attachment.isAudio()) {
|
|
||||||
showPlayerState(attachment.getUri(context));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putSerializable("file", attachment.getFile(context));
|
args.putSerializable("file", attachment.getFile(context));
|
||||||
args.putString("type", attachment.getMimeType());
|
args.putString("type", attachment.getMimeType());
|
||||||
|
@ -132,6 +128,22 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
|
||||||
String type = args.getString("type");
|
String type = args.getString("type");
|
||||||
int max = args.getInt("max");
|
int max = args.getInt("max");
|
||||||
|
|
||||||
|
args.putLong("size", file.length());
|
||||||
|
|
||||||
|
if (type != null &&
|
||||||
|
(type.startsWith("audio/") || type.startsWith("video")))
|
||||||
|
// https://developer.android.com/reference/android/media/MediaMetadataRetriever
|
||||||
|
try (MediaMetadataRetriever ret = new MediaMetadataRetriever()) {
|
||||||
|
ret.setDataSource(file.getAbsolutePath());
|
||||||
|
|
||||||
|
String value = ret.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
|
||||||
|
Integer duration = Helper.parseInt(value);
|
||||||
|
if (duration != null)
|
||||||
|
args.putInt("duration", duration);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.w(ex);
|
||||||
|
}
|
||||||
|
|
||||||
if ("application/pdf".equals(type)) {
|
if ("application/pdf".equals(type)) {
|
||||||
// https://developer.android.com/reference/android/graphics/pdf/PdfRenderer
|
// https://developer.android.com/reference/android/graphics/pdf/PdfRenderer
|
||||||
try (ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)) {
|
try (ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)) {
|
||||||
|
@ -172,8 +184,6 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
|
||||||
if ("image/webp".equalsIgnoreCase(type) && !webp)
|
if ("image/webp".equalsIgnoreCase(type) && !webp)
|
||||||
return context.getDrawable(R.drawable.twotone_image_not_supported_24);
|
return context.getDrawable(R.drawable.twotone_image_not_supported_24);
|
||||||
|
|
||||||
args.putLong("size", file.length());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inJustDecodeBounds = true;
|
options.inJustDecodeBounds = true;
|
||||||
|
@ -208,7 +218,9 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onExecuted(Bundle args, Drawable image) {
|
protected void onExecuted(Bundle args, Drawable image) {
|
||||||
if (image == null) {
|
if (attachment.isAudio())
|
||||||
|
showPlayerState(attachment.getUri(context));
|
||||||
|
else if (image == null) {
|
||||||
String type = args.getString("type");
|
String type = args.getString("type");
|
||||||
if ("application/pdf".equals(type))
|
if ("application/pdf".equals(type))
|
||||||
ivImage.setImageResource(R.drawable.twotone_article_24);
|
ivImage.setImageResource(R.drawable.twotone_article_24);
|
||||||
|
@ -249,10 +261,17 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
|
||||||
long size = args.getLong("size");
|
long size = args.getLong("size");
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
if (sb.length() > 0)
|
if (sb.length() > 0)
|
||||||
sb.append(" \u2013 "); // –
|
sb.append(' ');
|
||||||
sb.append(Helper.humanReadableByteCount(size));
|
sb.append(Helper.humanReadableByteCount(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int duration = args.getInt("duration");
|
||||||
|
if (duration > 0) {
|
||||||
|
if (sb.length() > 0)
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(Helper.formatDuration(duration));
|
||||||
|
}
|
||||||
|
|
||||||
if (sb.length() > 0) {
|
if (sb.length() > 0) {
|
||||||
tvProperties.setText(sb);
|
tvProperties.setText(sb);
|
||||||
tvProperties.setVisibility(View.VISIBLE);
|
tvProperties.setVisibility(View.VISIBLE);
|
||||||
|
|
Loading…
Reference in New Issue