당신이 원한다면 당신은 MetaDataRetriever
을 사용할 수 있습니다 ... 그것은 (내 경험) 노래에서 메타 데이터를 검색 할 수있는보다 완벽한 방법 (이 링크 https://developer.android.com/reference/android/media/MediaMetadataRetriever.html 더 볼 수 있습니다) ... 나는이 같은 것을 썼다 내 사업이 당신을 도울 수 있기를 바랍니다 :
public void MetSongRetriever() {
//MediaPlayerPlay is the context, I shared a function i wrote myself
//Just like myUri is the path of the song (external storage in my case)
mMediaData.setDataSource(MediaPlayerPlay.this, myUri);
try {
mNameSong.setText(mMediaData.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE));
mBandName.setText(mMediaData.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST));
art = metaRetriver.getEmbeddedPicture();
Bitmap songImage = BitmapFactory.decodeByteArray(art, 0, art.length);
mCoverImage.setImageBitmap(songImage);
mAlbumName.setText(metaRetriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
mGenre.setText(metaRetriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
}
catch (Exception e) {
//set all the text Uknown, like "Unknown title" and so on
//And the background for the image grey
}
}
업데이트 : 내가 제대로 이해하면 글쎄, 당신은 제목, 앨범, 밴드, 장르 등의 정보를 보여주고 싶어하고 그래서 각 노래에 오른쪽 목록? 저는 보통 ListView를 사용합니다 ... ListView +를 사용하여 정보를 정리하는 + 사용자 정의 클래스를 만들고 ArrayAdapter를 사용하여 클래스 구조를 상속하고 ListView에 표시 할 수 있습니다 (제목, 밴드 앨범 내 경우에 노래가 저장된 경로, 외부 저장, 당신은)이 라인을 다음 당신이 원하는
public class Songs {
public String mSongname, mBandName, mAlbumName, mPathSong;
public Songs(String songName, String bandName, String albumName, String pathSong) {
mSongname = songName;
mBandName = bandName;
mAlbumName = albumName;
mPathSong = pathSong;
}
public void setSongname(String songname) {
mSongname = songname;
}
public void setBandName(String bandName) {
mBandName = bandName;
}
public void setAlbumName(String albumName) {
mAlbumName = albumName;
}
public void setPathSong(String pathSong) {
mPathSong = pathSong;
}
public String getSongname() {
return mSongname;
}
public String getBandName() {
return mBandName;
}
public String getAlbumName() {
return mAlbumName;
}
public String getPathSong() {
return mPathSong;
}
SongsAdapter.java
Songs.java을 추가 할 수 있습니다
public class SongsAdapter extends ArrayAdapter<Songs> { public SongsAdapter(Context context, ArrayList<Songs> mySongs) { super(context, 0, mySongs); } @Override public View getView(int position, View convertView, ViewGroup parent) { //Storing the data from the current position Songs mySongs = getItem(position); //Check if the convertview is reused, otherwise i load it if(convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_songs, parent, false); } //Filling the structure with data TextView SongTitle = (TextView) convertView.findViewById(R.id.ID_item_songs_title); TextView BandName = (TextView) convertView.findViewById(R.id.ID_item_songs_band); TextView AlbumName = (TextView) convertView.findViewById(R.id.ID_item_songs_album); TextView PathName = (TextView) convertView.findViewById(R.id.ID_item_songs_path); //Inserting the data in the template view SongTitle.setText(mySongs.mSongname); BandName.setText(mySongs.mBandName); AlbumName.setText(mySongs.mAlbumName); PathName.setText(mySongs.mPathSong); //Return of the view for visualisation purpose return convertView; } }
다음 하나는 내가
public void getMusicList() {
int i = 0;
//I used the content resolver to get access to another part of the device, in my case the external storage
ContentResolver mContentResolver = getContentResolver();
//Taking the external storage general path
Uri mSongUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
//The cursor is used to point to a certain row in the temp database, so you can store just parts of it and not the whole database (efficiency maxed)
Cursor mSongCursor = getContentResolver().query(mSongUri, null, null, null, null, null);
if ((mSongCursor != null) && mSongCursor.moveToFirst()) {
//Gathering the index of each column for each info i want
int mTempSongTitle = mSongCursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
int mTempBand = mSongCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int mTempAlbum = mSongCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM);
int mTempLocationPath = mSongCursor.getColumnIndex(MediaStore.Audio.Media.DATA);
do {
//Gathering the real info based on the index
String mCurrentTitle = mSongCursor.getString(mTempSongTitle);
String mCurrentBand = mSongCursor.getString(mTempBand);
String mCurrentAlbum = mSongCursor.getString(mTempAlbum);
String mCurrentPath = mSongCursor.getString(mTempLocationPath);
mListOfPaths[i] = mCurrentPath;
i++;
Songs newSong = new Songs(mCurrentTitle, mCurrentBand, mCurrentAlbum, mCurrentPath);
adapter.add(newSong);
} while (mSongCursor.moveToNext());
}
}
(난 그냥, 문자열 배열에있는 모든 노래 '경로를 저장하는 다른 활동에 사용할 수 있도록, 당신을 위해 유용하지 인덱스를 사용) 데이터를 검색하는 데 사용되는 기능입니다 그리고이 마지막 기능이 마지막으로 이전 기능
public void doStuff() {
mSongNames = (ListView) findViewById(R.id.ID_MPM_listView);
mSongNames.setAdapter(adapter);
getMusicList();
//The event it will occur when you click on an item of the listView
mSongNames.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent mMediaPlayerPlayIntent = new Intent(MediaPlayerMain.this, MediaPlayerPlay.class);
mMediaPlayerPlayIntent.putExtra("ExtraPosition", position);
mMediaPlayerPlayIntent.putExtra("StringArray", mListOfPaths);
startActivity(mMediaPlayerPlayIntent);
}
});
}
에 수집 된 모든 데이터를 표시하는 데 사용됩니다 당신이 https://developer.android.com/reference/android/media/MediaMetadataRetriever ([MediaMetaDataRetriever]와 보셨습니까 .html)? 'MediaMetadataRetriever media = new MediaMetadataRetriever(); media.setDataSource ("file.mp3"); media.extractMetadata (METADATA_KEY_GENRE); ' –
앨범 장르가 아닌 노래 장르에 해당합니다. – Eamonn