import java.net.URI; //导入方法依赖的package包/类
@Override
public DIDLObject browseMeta(YaaccContentDirectory contentDirectory,
String myId) {
Item result = null;
String[] projection = {MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.MIME_TYPE, MediaStore.Audio.Media.SIZE,
MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.DURATION};
String selection = MediaStore.Audio.Media._ID + "=?";
String[] selectionArgs = new String[]{myId
.substring(ContentDirectoryIDs.MUSIC_ALL_TITLES_ITEM_PREFIX
.getId().length())};
Cursor mediaCursor = contentDirectory
.getContext()
.getContentResolver()
.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,
selection, selectionArgs, null);
if (mediaCursor != null) {
mediaCursor.moveToFirst();
String id = mediaCursor.getString(mediaCursor
.getColumnIndex(MediaStore.Audio.Media._ID));
String name = mediaCursor.getString(mediaCursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
Long size = Long.valueOf(mediaCursor.getString(mediaCursor
.getColumnIndex(MediaStore.Audio.Media.SIZE)));
String album = mediaCursor.getString(mediaCursor
.getColumnIndex(MediaStore.Audio.Media.ALBUM));
String albumId = mediaCursor.getString(mediaCursor
.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
String title = mediaCursor.getString(mediaCursor
.getColumnIndex(MediaStore.Audio.Media.TITLE));
String artist = mediaCursor.getString(mediaCursor
.getColumnIndex(MediaStore.Audio.Media.ARTIST));
String duration = mediaCursor.getString(mediaCursor
.getColumnIndex(MediaStore.Audio.Media.DURATION));
duration = contentDirectory.formatDuration(duration);
Log.d(getClass().getName(),
"Mimetype: "
+ mediaCursor.getString(mediaCursor
.getColumnIndex(MediaStore.Audio.Media.MIME_TYPE)));
MimeType mimeType = MimeType.valueOf(mediaCursor
.getString(mediaCursor
.getColumnIndex(MediaStore.Audio.Media.MIME_TYPE)));
// file parameter only needed for media players which decide
// the
// ability of playing a file by the file extension
String uri = getUriString(contentDirectory, id, mimeType);
URI albumArtUri = URI.create("http://"
+ contentDirectory.getIpAddress() + ":"
+ YaaccUpnpServerService.PORT + "/?album=" + albumId);
Res resource = new Res(mimeType, size, uri);
resource.setDuration(duration);
MusicTrack musicTrack = new MusicTrack(
ContentDirectoryIDs.MUSIC_ALL_TITLES_ITEM_PREFIX.getId()
+ id,
ContentDirectoryIDs.MUSIC_ALL_TITLES_FOLDER.getId(), title
+ "-(" + name + ")", "", album, artist, resource);
musicTrack
.replaceFirstProperty(new UPNP.ALBUM_ART_URI(albumArtUri));
result = musicTrack;
Log.d(getClass().getName(), "MusicTrack: " + id + " Name: " + name
+ " uri: " + uri);
mediaCursor.close();
} else {
Log.d(getClass().getName(), "Item " + myId + " not found.");
}
return result;
}