MediaMetaDataRetriever: - MediaMetaDataRetriever android . - "android.media.MediaMetadataRetriever". , :
, sd-card.
byte[] art;
art = metaRetriver.getEmbeddedPicture();
.
Bitmap songImage = BitmapFactory.decodeByteArray(art, 0, art.length);
Bitmap, ImageView, .
ImageView album_art;
TextView album, artist, genre;
MediaMetadataRetriever metaRetriver;
byte[] art;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getInit();
metaRetriver = new MediaMetadataRetriever();
metaRetriver.setDataSource("/sdcard/audio.mp3");
try {
art = metaRetriver.getEmbeddedPicture();
Bitmap songImage = BitmapFactory
.decodeByteArray(art, 0, art.length);
album_art.setImageBitmap(songImage);
album.setText(metaRetriver
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
artist.setText(metaRetriver
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST));
genre.setText(metaRetriver
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
} catch (Exception e) {
album_art.setBackgroundColor(Color.GRAY);
album.setText("Unknown Album");
artist.setText("Unknown Artist");
genre.setText("Unknown Genre");
}
}
public void getInit() {
album_art = (ImageView) findViewById(R.id.album_art);
album = (TextView) findViewById(R.id.Album);
artist = (TextView) findViewById(R.id.artist_name);
genre = (TextView) findViewById(R.id.genre);
}
main.xml
<? xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/album_art_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="60dp"
android:text="Album Art"
android:textSize="18dp" />
<ImageView
android:id="@+id/album_art"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="10dp" />
<TextView
android:id="@+id/album_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/album_art_text"
android:layout_below="@+id/album_art"
android:layout_marginTop="24dp"
android:text="Album Name :"
android:textSize="18dp" />
<TextView
android:id="@+id/artist_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/album_name_text"
android:layout_below="@+id/album_name_text"
android:layout_marginTop="43dp"
android:text="Artist Name :"
android:textSize="18dp" />
<TextView
android:id="@+id/genre_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/artist_name_text"
android:layout_below="@+id/artist_name_text"
android:layout_marginTop="39dp"
android:text="Genre :"
android:textSize="18dp" />
<TextView
android:id="@+id/genre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/genre_text"
android:layout_alignBottom="@+id/genre_text"
android:layout_toRightOf="@+id/album_art_text"
android:text="null"
android:textSize="18dp" />
<TextView
android:id="@+id/Album"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/artist_name_text"
android:layout_alignLeft="@+id/album_art"
android:text="null"
android:textSize="18dp" />
<TextView
android:id="@+id/artist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/genre_text"
android:layout_alignLeft="@+id/Album"
android:text="null"
android:textSize="18dp" />
</RelativeLayout>