forked from mirror/monocles_chat
Show metadata of audio files when available
This commit is contained in:
parent
db825530e6
commit
82a57ffcf1
2 changed files with 28 additions and 1 deletions
|
@ -9,6 +9,7 @@ import android.hardware.SensorEvent;
|
|||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
|
@ -114,7 +115,14 @@ public class AudioPlayer
|
|||
|
||||
private boolean init(final ViewHolder viewHolder, final Message message) {
|
||||
MessageAdapter.setTextColor(viewHolder.runtime, viewHolder.bubbleColor);
|
||||
MessageAdapter.setTextColor(viewHolder.title, viewHolder.bubbleColor);
|
||||
viewHolder.progress.setOnSeekBarChangeListener(this);
|
||||
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
|
||||
try {
|
||||
mediaMetadataRetriever.setDataSource(message.getRelativeFilePath());
|
||||
} catch (Exception e) {
|
||||
Log.w(Config.LOGTAG, e);
|
||||
}
|
||||
final ColorStateList color =
|
||||
MessageAdapter.bubbleToOnSurfaceColorStateList(
|
||||
viewHolder.progress, viewHolder.bubbleColor);
|
||||
|
@ -140,6 +148,9 @@ public class AudioPlayer
|
|||
MessageAdapter.setImageTint(viewHolder.playPause, viewHolder.bubbleColor);
|
||||
viewHolder.playPause.setContentDescription(context.getString(R.string.play_audio));
|
||||
viewHolder.runtime.setText(formatTime(message.getFileParams().runtime));
|
||||
if (mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST) != null) {
|
||||
viewHolder.title.setText(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST) + " - " + mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
|
||||
}
|
||||
viewHolder.progress.setProgress(0);
|
||||
viewHolder.progress.setEnabled(false);
|
||||
return false;
|
||||
|
@ -461,6 +472,7 @@ public class AudioPlayer
|
|||
|
||||
public static class ViewHolder {
|
||||
private TextView runtime;
|
||||
private TextView title;
|
||||
private SeekBar progress;
|
||||
private ImageButton playPause;
|
||||
private MessageAdapter.BubbleColor bubbleColor = MessageAdapter.BubbleColor.SURFACE;
|
||||
|
@ -473,6 +485,7 @@ public class AudioPlayer
|
|||
}
|
||||
final ViewHolder viewHolder = new ViewHolder();
|
||||
viewHolder.runtime = audioPlayer.findViewById(R.id.runtime);
|
||||
viewHolder.title = audioPlayer.findViewById(R.id.title);
|
||||
viewHolder.progress = audioPlayer.findViewById(R.id.progress);
|
||||
viewHolder.playPause = audioPlayer.findViewById(R.id.play_pause);
|
||||
audioPlayer.setTag(R.id.TAG_AUDIO_PLAYER_VIEW_HOLDER, viewHolder);
|
||||
|
|
|
@ -137,14 +137,28 @@
|
|||
android:layout_marginBottom="16dp"
|
||||
android:textAppearance="?textAppearanceBodySmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxWidth="160dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginStart="36dp"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:scrollHorizontally="true"
|
||||
android:textAppearance="?textAppearanceBodySmall" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/runtime"
|
||||
android:layout_below="@+id/title"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@+id/play_pause"
|
||||
android:progress="100" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</merge>
|
||||
|
|
Loading…
Reference in a new issue