1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.support.model.item;
17
18 import org.fourthline.cling.support.model.Person;
19 import org.fourthline.cling.support.model.PersonWithRole;
20 import org.fourthline.cling.support.model.Res;
21 import org.fourthline.cling.support.model.StorageMedium;
22 import org.fourthline.cling.support.model.container.Container;
23
24 import java.util.List;
25
26 import static org.fourthline.cling.support.model.DIDLObject.Property.DC;
27 import static org.fourthline.cling.support.model.DIDLObject.Property.UPNP;
28
29
30
31
32 public class MusicTrack extends AudioItem {
33
34 public static final Class CLASS = new Class("object.item.audioItem.musicTrack");
35
36 public MusicTrack() {
37 setClazz(CLASS);
38 }
39
40 public MusicTrack(Item other) {
41 super(other);
42 }
43
44 public MusicTrack(String id, Container parent, String title, String creator, String album, String artist, Res... resource) {
45 this(id, parent.getId(), title, creator, album, artist, resource);
46 }
47
48 public MusicTrack(String id, Container parent, String title, String creator, String album, PersonWithRole artist, Res... resource) {
49 this(id, parent.getId(), title, creator, album, artist, resource);
50 }
51
52 public MusicTrack(String id, String parentID, String title, String creator, String album, String artist, Res... resource) {
53 this(id, parentID, title, creator, album, artist == null ? null : new PersonWithRole(artist), resource);
54 }
55
56 public MusicTrack(String id, String parentID, String title, String creator, String album, PersonWithRole artist, Res... resource) {
57 super(id, parentID, title, creator, resource);
58 setClazz(CLASS);
59 if (album != null)
60 setAlbum(album);
61 if (artist != null)
62 addProperty(new UPNP.ARTIST(artist));
63 }
64
65 public PersonWithRole getFirstArtist() {
66 return getFirstPropertyValue(UPNP.ARTIST.class);
67 }
68
69 public PersonWithRole[] getArtists() {
70 List<PersonWithRole> list = getPropertyValues(UPNP.ARTIST.class);
71 return list.toArray(new PersonWithRole[list.size()]);
72 }
73
74 public MusicTrack setArtists(PersonWithRole[] artists) {
75 removeProperties(UPNP.ARTIST.class);
76 for (PersonWithRole artist : artists) {
77 addProperty(new UPNP.ARTIST(artist));
78 }
79 return this;
80 }
81
82 public String getAlbum() {
83 return getFirstPropertyValue(UPNP.ALBUM.class);
84 }
85
86 public MusicTrack setAlbum(String album) {
87 replaceFirstProperty(new UPNP.ALBUM(album));
88 return this;
89 }
90
91 public Integer getOriginalTrackNumber() {
92 return getFirstPropertyValue(UPNP.ORIGINAL_TRACK_NUMBER.class);
93 }
94
95 public MusicTrack setOriginalTrackNumber(Integer number) {
96 replaceFirstProperty(new UPNP.ORIGINAL_TRACK_NUMBER(number));
97 return this;
98 }
99
100 public String getFirstPlaylist() {
101 return getFirstPropertyValue(UPNP.PLAYLIST.class);
102 }
103
104 public String[] getPlaylists() {
105 List<String> list = getPropertyValues(UPNP.PLAYLIST.class);
106 return list.toArray(new String[list.size()]);
107 }
108
109 public MusicTrack setPlaylists(String[] playlists) {
110 removeProperties(UPNP.PLAYLIST.class);
111 for (String s : playlists) {
112 addProperty(new UPNP.PLAYLIST(s));
113 }
114 return this;
115 }
116
117 public StorageMedium getStorageMedium() {
118 return getFirstPropertyValue(UPNP.STORAGE_MEDIUM.class);
119 }
120
121 public MusicTrack setStorageMedium(StorageMedium storageMedium) {
122 replaceFirstProperty(new UPNP.STORAGE_MEDIUM(storageMedium));
123 return this;
124 }
125
126 public Person getFirstContributor() {
127 return getFirstPropertyValue(DC.CONTRIBUTOR.class);
128 }
129
130 public Person[] getContributors() {
131 List<Person> list = getPropertyValues(DC.CONTRIBUTOR.class);
132 return list.toArray(new Person[list.size()]);
133 }
134
135 public MusicTrack setContributors(Person[] contributors) {
136 removeProperties(DC.CONTRIBUTOR.class);
137 for (Person p : contributors) {
138 addProperty(new DC.CONTRIBUTOR(p));
139 }
140 return this;
141 }
142
143 public String getDate() {
144 return getFirstPropertyValue(DC.DATE.class);
145 }
146
147 public MusicTrack setDate(String date) {
148 replaceFirstProperty(new DC.DATE(date));
149 return this;
150 }
151
152 }