use of org.fourthline.cling.support.model.PersonWithRole in project BeyondUPnP by kevinshine.
the class MediaResourceDao method getAudioList.
public static List<Item> getAudioList(String serverUrl, String parentId) {
List<Item> items = new ArrayList<>();
//Query all track,add to items
Cursor c = BeyondApplication.getApplication().getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.TITLE);
c.moveToFirst();
while (!c.isAfterLast()) {
long id = c.getLong(c.getColumnIndex(MediaStore.Audio.Media._ID));
String title = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
String creator = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
String album = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
String data = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
//Remove SDCard path
data = data.replaceFirst(storageDir, "");
//Replace file name by "id.ext"
String fileName = data.substring(data.lastIndexOf(File.separator));
String ext = fileName.substring(fileName.lastIndexOf("."));
data = data.replace(fileName, File.separator + id + ext);
String mimeType = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));
long size = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));
long duration = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
//Get duration string
String durationStr = ModelUtil.toTimeString(duration);
//Compose audio url
String url = serverUrl + File.separator + "audio" + File.separator + data;
Res res = new Res(mimeType, size, durationStr, null, url);
items.add(new MusicTrack(String.valueOf(id), parentId, title, creator, album, new PersonWithRole(creator), res));
c.moveToNext();
}
return items;
}
Aggregations