org.fourthline.cling.support.model.item.MusicTrack Java Examples

The following examples show how to use org.fourthline.cling.support.model.item.MusicTrack. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: airsonic-advanced   Author: airsonic-advanced   File: DispatchingContentDirectory.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Item createItem(MediaFile song) {
    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.getId())));

    return item;
}
 
Example #2
Source Project: airsonic-advanced   Author: airsonic-advanced   File: MediaFileUpnpProcessor.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Item createItem(MediaFile song) {
    MediaFile parent = getMediaFileService().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(getDispatcher().getAlbumProcessor().getAlbumArtists(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(getDispatcher().createResourceForSong(song)));
    item.setDescription(song.getComment());
    item.addProperty(new DIDLObject.Property.UPNP.ALBUM_ART_URI(getDispatcher().getAlbumProcessor().getAlbumArtURI(parent.getId())));

    return item;
}
 
Example #3
Source Project: airsonic-advanced   Author: airsonic-advanced   File: FolderBasedContentDirectory.java    License: GNU General Public License v3.0 6 votes vote down vote up
private Item createItem(MediaFile song) {
    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;
}
 
Example #4
Source Project: airsonic   Author: airsonic   File: DispatchingContentDirectory.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Item createItem(MediaFile song) {
    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.getId())));

    return item;
}
 
Example #5
Source Project: airsonic   Author: airsonic   File: MediaFileUpnpProcessor.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Item createItem(MediaFile song) {
    MediaFile parent = getMediaFileService().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(getDispatcher().getAlbumProcessor().getAlbumArtists(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(getDispatcher().createResourceForSong(song)));
    item.setDescription(song.getComment());
    item.addProperty(new DIDLObject.Property.UPNP.ALBUM_ART_URI(getDispatcher().getAlbumProcessor().getAlbumArtURI(parent.getId())));

    return item;
}
 
Example #6
Source Project: airsonic   Author: airsonic   File: FolderBasedContentDirectory.java    License: GNU General Public License v3.0 6 votes vote down vote up
private Item createItem(MediaFile song) {
    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;
}
 
Example #7
Source Project: subsonic   Author: sindremehus   File: FolderBasedContentDirectory.java    License: GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #8
Source Project: TVRemoteIME   Author: kingthy   File: MusicAlbum.java    License: GNU General Public License v2.0 5 votes vote down vote up
public MusicTrack[] getMusicTracks() {
    List<MusicTrack> list = new ArrayList();
    for (Item item : getItems()) {
        if (item instanceof MusicTrack) list.add((MusicTrack)item);
    }
    return list.toArray(new MusicTrack[list.size()]);
}
 
Example #9
Source Project: TVRemoteIME   Author: kingthy   File: MusicAlbum.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void addMusicTracks(MusicTrack[] musicTracks) {
    if (musicTracks != null) {
        for (MusicTrack musicTrack : musicTracks) {
            musicTrack.setAlbum(getTitle());
            addItem(musicTrack);
        }
    }
}
 
Example #10
Source Project: BeyondUPnP   Author: kevinshine   File: MediaResourceDao.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #11
Source Project: DroidDLNA   Author: offbye   File: MusicAlbum.java    License: GNU General Public License v3.0 5 votes vote down vote up
public MusicTrack[] getMusicTracks() {
    List<MusicTrack> list = new ArrayList();
    for (Item item : getItems()) {
        if (item instanceof MusicTrack) list.add((MusicTrack)item);
    }
    return list.toArray(new MusicTrack[list.size()]);
}
 
Example #12
Source Project: DroidDLNA   Author: offbye   File: MusicAlbum.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void addMusicTracks(MusicTrack[] musicTracks) {
    if (musicTracks != null) {
        for (MusicTrack musicTrack : musicTracks) {
            musicTrack.setAlbum(getTitle());
            addItem(musicTrack);
        }
    }
}
 
Example #13
Source Project: TVRemoteIME   Author: kingthy   File: DIDLContent.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected List<Item> replaceGenericItems(List<Item> genericItems) {
    List<Item> specificItems = new ArrayList();

    for (Item genericItem : genericItems) {
        String genericType = genericItem.getClazz().getValue();

        if (AudioItem.CLASS.getValue().equals(genericType)) {
            specificItems.add(new AudioItem(genericItem));
        } else if (MusicTrack.CLASS.getValue().equals(genericType)) {
            specificItems.add(new MusicTrack(genericItem));
        } else if (AudioBook.CLASS.getValue().equals(genericType)) {
            specificItems.add(new AudioBook(genericItem));
        } else if (AudioBroadcast.CLASS.getValue().equals(genericType)) {
            specificItems.add(new AudioBroadcast(genericItem));

        } else if (VideoItem.CLASS.getValue().equals(genericType)) {
            specificItems.add(new VideoItem(genericItem));
        } else if (Movie.CLASS.getValue().equals(genericType)) {
            specificItems.add(new Movie(genericItem));
        } else if (VideoBroadcast.CLASS.getValue().equals(genericType)) {
            specificItems.add(new VideoBroadcast(genericItem));
        } else if (MusicVideoClip.CLASS.getValue().equals(genericType)) {
            specificItems.add(new MusicVideoClip(genericItem));

        } else if (ImageItem.CLASS.getValue().equals(genericType)) {
            specificItems.add(new ImageItem(genericItem));
        } else if (Photo.CLASS.getValue().equals(genericType)) {
            specificItems.add(new Photo(genericItem));

        } else if (PlaylistItem.CLASS.getValue().equals(genericType)) {
            specificItems.add(new PlaylistItem(genericItem));

        } else if (TextItem.CLASS.getValue().equals(genericType)) {
            specificItems.add(new TextItem(genericItem));

        } else {
            specificItems.add(genericItem);
        }
    }

    return specificItems;
}
 
Example #14
Source Project: TVRemoteIME   Author: kingthy   File: MusicAlbum.java    License: GNU General Public License v2.0 4 votes vote down vote up
public MusicAlbum(String id, Container parent, String title, String creator, Integer childCount) {
    this(id, parent.getId(), title, creator, childCount, new ArrayList<MusicTrack>());
}
 
Example #15
Source Project: TVRemoteIME   Author: kingthy   File: MusicAlbum.java    License: GNU General Public License v2.0 4 votes vote down vote up
public MusicAlbum(String id, Container parent, String title, String creator, Integer childCount, List<MusicTrack> musicTracks) {
    this(id, parent.getId(), title, creator, childCount, musicTracks);
}
 
Example #16
Source Project: TVRemoteIME   Author: kingthy   File: MusicAlbum.java    License: GNU General Public License v2.0 4 votes vote down vote up
public MusicAlbum(String id, String parentID, String title, String creator, Integer childCount) {
    this(id, parentID, title, creator, childCount, new ArrayList<MusicTrack>());
}
 
Example #17
Source Project: TVRemoteIME   Author: kingthy   File: MusicAlbum.java    License: GNU General Public License v2.0 4 votes vote down vote up
public MusicAlbum(String id, String parentID, String title, String creator, Integer childCount, List<MusicTrack> musicTracks) {
    super(id, parentID, title, creator, childCount);
    setClazz(CLASS);
    addMusicTracks(musicTracks);
}
 
Example #18
Source Project: TVRemoteIME   Author: kingthy   File: MusicAlbum.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void addMusicTracks(List<MusicTrack> musicTracks) {
    addMusicTracks(musicTracks.toArray(new MusicTrack[musicTracks.size()]));
}
 
Example #19
Source Project: HPlayer   Author: hezhubo   File: GenerateContentTask.java    License: Apache License 2.0 4 votes vote down vote up
/**
     * 添加音频
     */
    private void addAudioContent(Context context, ContentNode rootNode) {

        Container audioContainer = new Container(ContentTree.AUDIO_ID,
                ContentTree.ROOT_ID, "Audios", "HPlayer MediaServer",
                new DIDLObject.Class("object.container"), 0);
        audioContainer.setRestricted(true);
        audioContainer.setWriteStatus(WriteStatus.NOT_WRITABLE);

        rootNode.getContainer().addContainer(audioContainer);
        rootNode.getContainer().setChildCount(
                rootNode.getContainer().getChildCount() + 1);
        ContentTree.addNode(ContentTree.AUDIO_ID, new ContentNode(
                ContentTree.AUDIO_ID, audioContainer));

        Cursor cursor = context.getContentResolver()
                .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                        null, null, null, null);
        if (cursor == null) {
            return;
        }

        while (cursor.moveToNext()) {
            String id = ContentTree.AUDIO_PREFIX
                    + cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
            String title = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
            String creator = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
            String filePath = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
            String mimeType = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));
            long size = cursor.getLong(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));
            long duration = cursor.getLong(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
            String album = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
            Res res = new Res(new MimeType(mimeType.substring(0, mimeType.indexOf('/')),
                    mimeType.substring(mimeType.indexOf('/') + 1)), size,
                    "http://" + address + "/" + id);
            res.setDuration(duration / (1000 * 60 * 60) + ":"
                    + (duration % (1000 * 60 * 60)) / (1000 * 60) + ":"
                    + (duration % (1000 * 60)) / 1000);

            // Music Track must have `artist' with role field, or
            // DIDLParser().generate(didl) will throw nullpointException
            MusicTrack musicTrack = new MusicTrack(id,
                    ContentTree.AUDIO_ID, title, creator, album,
                    new PersonWithRole(creator, "Performer"), res);
            audioContainer.addItem(musicTrack);
            audioContainer.setChildCount(audioContainer.getChildCount() + 1);
            ContentTree.addNode(id, new ContentNode(id, musicTrack, filePath));

//            Log.d(TAG, "added audio item " + title + "from " + filePath);
        }

        cursor.close();
    }
 
Example #20
Source Project: DroidDLNA   Author: offbye   File: DIDLContent.java    License: GNU General Public License v3.0 4 votes vote down vote up
protected List<Item> replaceGenericItems(List<Item> genericItems) {
    List<Item> specificItems = new ArrayList();

    for (Item genericItem : genericItems) {
        String genericType = genericItem.getClazz().getValue();

        if (AudioItem.CLASS.getValue().equals(genericType)) {
            specificItems.add(new AudioItem(genericItem));
        } else if (MusicTrack.CLASS.getValue().equals(genericType)) {
            specificItems.add(new MusicTrack(genericItem));
        } else if (AudioBook.CLASS.getValue().equals(genericType)) {
            specificItems.add(new AudioBook(genericItem));
        } else if (AudioBroadcast.CLASS.getValue().equals(genericType)) {
            specificItems.add(new AudioBroadcast(genericItem));

        } else if (VideoItem.CLASS.getValue().equals(genericType)) {
            specificItems.add(new VideoItem(genericItem));
        } else if (Movie.CLASS.getValue().equals(genericType)) {
            specificItems.add(new Movie(genericItem));
        } else if (VideoBroadcast.CLASS.getValue().equals(genericType)) {
            specificItems.add(new VideoBroadcast(genericItem));
        } else if (MusicVideoClip.CLASS.getValue().equals(genericType)) {
            specificItems.add(new MusicVideoClip(genericItem));

        } else if (ImageItem.CLASS.getValue().equals(genericType)) {
            specificItems.add(new ImageItem(genericItem));
        } else if (Photo.CLASS.getValue().equals(genericType)) {
            specificItems.add(new Photo(genericItem));

        } else if (PlaylistItem.CLASS.getValue().equals(genericType)) {
            specificItems.add(new PlaylistItem(genericItem));

        } else if (TextItem.CLASS.getValue().equals(genericType)) {
            specificItems.add(new TextItem(genericItem));

        } else {
            specificItems.add(genericItem);
        }
    }

    return specificItems;
}
 
Example #21
Source Project: DroidDLNA   Author: offbye   File: MusicAlbum.java    License: GNU General Public License v3.0 4 votes vote down vote up
public MusicAlbum(String id, Container parent, String title, String creator, Integer childCount) {
    this(id, parent.getId(), title, creator, childCount, new ArrayList<MusicTrack>());
}
 
Example #22
Source Project: DroidDLNA   Author: offbye   File: MusicAlbum.java    License: GNU General Public License v3.0 4 votes vote down vote up
public MusicAlbum(String id, Container parent, String title, String creator, Integer childCount, List<MusicTrack> musicTracks) {
    this(id, parent.getId(), title, creator, childCount, musicTracks);
}
 
Example #23
Source Project: DroidDLNA   Author: offbye   File: MusicAlbum.java    License: GNU General Public License v3.0 4 votes vote down vote up
public MusicAlbum(String id, String parentID, String title, String creator, Integer childCount) {
    this(id, parentID, title, creator, childCount, new ArrayList<MusicTrack>());
}
 
Example #24
Source Project: DroidDLNA   Author: offbye   File: MusicAlbum.java    License: GNU General Public License v3.0 4 votes vote down vote up
public MusicAlbum(String id, String parentID, String title, String creator, Integer childCount, List<MusicTrack> musicTracks) {
    super(id, parentID, title, creator, childCount);
    setClazz(CLASS);
    addMusicTracks(musicTracks);
}
 
Example #25
Source Project: DroidDLNA   Author: offbye   File: MusicAlbum.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void addMusicTracks(List<MusicTrack> musicTracks) {
    addMusicTracks(musicTracks.toArray(new MusicTrack[musicTracks.size()]));
}