Search in sources :

Example 1 with MusicTrack

use of org.fourthline.cling.support.model.item.MusicTrack 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;
}
Also used : Item(org.fourthline.cling.support.model.item.Item) Res(org.fourthline.cling.support.model.Res) MusicTrack(org.fourthline.cling.support.model.item.MusicTrack) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) PersonWithRole(org.fourthline.cling.support.model.PersonWithRole)

Example 2 with MusicTrack

use of org.fourthline.cling.support.model.item.MusicTrack in project libresonic by Libresonic.

the class FolderBasedContentDirectory method createItem.

private Item createItem(MediaFile song) throws Exception {
    MediaFile parent = mediaFileService.getParentOf(song);
    MusicTrack item = new MusicTrack();
    item.setId(String.valueOf(song.getId()));
    item.setParentID(String.valueOf(parent.getId()));
    item.setTitle(song.getTitle());
    item.setAlbum(song.getAlbumName());
    if (song.getArtist() != null) {
        item.setArtists(new PersonWithRole[] { new PersonWithRole(song.getArtist()) });
    }
    Integer year = song.getYear();
    if (year != null) {
        item.setDate(year + "-01-01");
    }
    item.setOriginalTrackNumber(song.getTrackNumber());
    if (song.getGenre() != null) {
        item.setGenres(new String[] { song.getGenre() });
    }
    item.setResources(Arrays.asList(createResourceForSong(song)));
    item.setDescription(song.getComment());
    item.addProperty(new DIDLObject.Property.UPNP.ALBUM_ART_URI(getAlbumArtUrl(parent)));
    return item;
}
Also used : MusicTrack(org.fourthline.cling.support.model.item.MusicTrack)

Aggregations

MusicTrack (org.fourthline.cling.support.model.item.MusicTrack)2 Cursor (android.database.Cursor)1 ArrayList (java.util.ArrayList)1 PersonWithRole (org.fourthline.cling.support.model.PersonWithRole)1 Res (org.fourthline.cling.support.model.Res)1 Item (org.fourthline.cling.support.model.item.Item)1