1 /* 2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package com.sun.javafx.ext.device.ios.ipod; 26 27 import java.util.Calendar; 28 import java.util.HashMap; 29 import java.util.Map; 30 31 import javafx.util.Duration; 32 import javafx.scene.image.Image; 33 34 /** 35 * The MediaItem class represents a single media item from the iPod library. It encapsulates each media item's 36 * properties, such as media type, genre, title, artist, lyrics, release date and others. For a full list of 37 * media item properties see the Methods section. 38 * <br/> 39 * In order to use a particular media item with the JavaFX Media API, use <code>MediaItem.getURL()</code> method 40 * to obtain a String representation of the media item's location that can be used to create an instance of the 41 * <code>javafx.scene.media.Media</code> class. 42 */ 43 public class MediaItem { 44 45 // enum values correspond directly to MPMediaItemPropertyMediaType values on iOS 46 47 /** 48 * The MediaItemType enum defines all possible media item types. Use this enum's values to create a MediaFilter 49 * filter that filters out media items according to their media type. 50 * <br/> 51 * See <code>MediaFilter</code> and <code>MediaFilter.MediaFilterType.MediaType</code> 52 */ 53 public static enum MediaItemType { 54 /** 55 * The media item contains music. 56 */ 57 Music (1 << 0), 58 /** 59 * The media item contains a podcast. 60 */ 61 Podcast (1 << 1), 62 /** 63 * The media item contains an audio book. 64 */ 65 AudioBook (1 << 2), 66 /** 67 * The media item contains an unspecified type of audio content. 68 */ 69 AnyAudio (0x00ff), 70 /** 71 * The media item contains a movie. 72 */ 73 Movie (1 << 8), 74 /** 75 * The media item contains a TV show. 76 */ 77 TVShow (1 << 9), 78 /** 79 * The media item contains a video podcast. 80 */ 81 VideoPodcast(1 << 10), 82 /** 83 * The media item contains a music video. 84 */ 85 MusicVideo (1 << 11), 86 /** 87 * The media item contains an iTunes U video. 88 */ 89 VideoITunesU(1 << 12), 90 /** 91 * The media item contains an unspecified type of video content. 92 */ 93 AnyVideo (0xff00), 94 /** 95 * The media item contains an unspecified type of audio. 96 */ 97 Any (~0); 98 99 // we need this mapping to be able to translate int values received from native code in an efficient manner 100 // calling values() would create a new array each time and lookup would be O(n) 101 private static final Map<Integer, MediaItemType> iosEnumCodes; 102 103 static { 104 iosEnumCodes = new HashMap<Integer, MediaItemType>(); 105 iosEnumCodes.put(Music.getValue(), Music); 106 iosEnumCodes.put(Podcast.getValue(), Podcast); 107 iosEnumCodes.put(AudioBook.getValue(), AudioBook); 108 iosEnumCodes.put(AnyAudio.getValue(), AnyAudio); 109 iosEnumCodes.put(Movie.getValue(), Movie); 110 iosEnumCodes.put(TVShow.getValue(), TVShow); 111 iosEnumCodes.put(VideoPodcast.getValue(), VideoPodcast); 112 iosEnumCodes.put(MusicVideo.getValue(), MusicVideo); 113 iosEnumCodes.put(VideoITunesU.getValue(), VideoITunesU); 114 iosEnumCodes.put(AnyVideo.getValue(), AnyVideo); 115 iosEnumCodes.put(Any.getValue(), Any); 116 } 117 118 private final int value; 119 120 private MediaItemType(int value) { 121 this.value = value; 122 } 123 124 /** 125 * Returns the integer value associated with this enum value. 126 * @return the integer value associated with this enum value. 127 */ 128 public int getValue() { 129 return value; 130 } 131 132 private static MediaItemType fromIntValue(int intValue) { 133 MediaItemType mediaItemType = null; 134 if (iosEnumCodes.containsKey(intValue)) { 135 mediaItemType = iosEnumCodes.get(intValue); 136 } 137 return mediaItemType; 138 } 139 } 140 141 private MediaItemType mediaType; 142 private String title; 143 private String albumTitle; 144 private String artist; 145 private String albumArtist; 146 private String genre; 147 private String composer; 148 private Duration playbackDuration; 149 private int albumTrackNumber; 150 private int albumTrackCount; 151 private int discNumber; 152 private int discCount; 153 private Image artwork; 154 private String lyrics; 155 private boolean isCompilation; 156 private Calendar releaseDate; 157 private int beatsPerMinute; 158 private String comments; 159 private String url; 160 161 MediaItem() { 162 163 } 164 165 /** 166 * Returns the media type of this media item. See the MediaItemType enum for possible values. 167 * @return the media type of this media item 168 */ 169 public MediaItemType getMediaType() { 170 return mediaType; 171 } 172 173 /** 174 * Returns the title (or name) of this media item. 175 * @return the title (or name) of this media item. 176 */ 177 public String getTitle() { 178 return title; 179 } 180 181 /** 182 * Returns the title of an album, such as "Thriller", as opposed to the title of an individual 183 * song on the album, such as "Beat It" 184 * @return the title of an album 185 */ 186 public String getAlbumTitle() { 187 return albumTitle; 188 } 189 190 /** 191 * Returns the performing artist(s) for this media item, which may vary from the primary artist for the album 192 * that a media item belongs to. For example, if the album artist is "Joseph Fable", the artist for one of 193 * the songs in the album may be "Joseph Fable featuring Thomas Smithson". 194 * @return the performing artist(s) for this media item 195 */ 196 public String getArtist() { 197 return artist; 198 } 199 200 /** 201 * Returns the primary performing artist for an album as a whole. 202 * @return the primary performing artist for an album as a whole 203 */ 204 public String getAlbumArtist() { 205 return albumArtist; 206 } 207 208 /** 209 * Returns the musical or film genre of this media item. 210 * @return the musical or film genre of this media item 211 */ 212 public String getGenre() { 213 return genre; 214 } 215 216 /** 217 * Returns the musical composer for this media item. 218 * @return the musical composer for this media item 219 */ 220 public String getComposer() { 221 return composer; 222 } 223 224 /** 225 * Returns the playback duration of this media item. 226 * @return the playback duration of this media item 227 */ 228 public Duration getPlaybackDuration() { 229 return playbackDuration; 230 } 231 232 /** 233 * Returns the track number of this media item, if it is part of an album. 234 * @return the track number of this media item 235 */ 236 public int getAlbumTrackNumber() { 237 return albumTrackNumber; 238 } 239 240 /** 241 * Returns the number of tracks in the album that contains this media item. 242 * @return the number of tracks in the album that contains this media item 243 */ 244 public int getAlbumTrackCount() { 245 return albumTrackCount; 246 } 247 248 /** 249 * Returns the disc number of this media item, provided it is part of a multi-disc album. 250 * @return the disc number of this media item 251 */ 252 public int getDiscNumber() { 253 return discNumber; 254 } 255 256 /** 257 * Returns the number of discs in the album that contains this media item. 258 * @return the number of discs in the album that contains this media item 259 */ 260 public int getDiscCount() { 261 return discCount; 262 } 263 264 /** 265 * Returns the artwork image for this media item. <strong>Not implemented</strong>. 266 * @return the artwork image for this media item 267 */ 268 public Image getArtwork() { 269 return artwork; 270 } 271 272 /** 273 * Returns the lyrics for this media item. 274 * @return the lyrics for this media item 275 */ 276 public String getLyrics() { 277 return lyrics; 278 } 279 280 /** 281 * Indicates whether this media item is part of a compilation or not. Corresponds to the 282 * "Part of a compilation" checkbox in the Info tab in the Get Info dialog in iTunes. 283 * @return a boolean value indicating whether this media item is part of a compilation 284 */ 285 public boolean isCompilation() { 286 return isCompilation; 287 } 288 289 /** 290 * Returns the date on which the media item was first publicly released. 291 * @return the date on which the media item was first publicly released 292 */ 293 public Calendar getReleaseDate() { 294 return releaseDate; 295 } 296 297 /** 298 * Returns the number of musical beats per minute for the media item, corresponding to the "BPM" field 299 * in the Info tab in the Get Info dialog in iTunes. 300 * @return the number of musical beats per minute (BPM) 301 */ 302 public int getBeatsPerMinute() { 303 return beatsPerMinute; 304 } 305 306 /** 307 * Returns textual information about this media item, corresponding to the "Comments" field in the 308 * Info tab in the Get Info dialog in iTunes. 309 * @return textual information about this media item 310 */ 311 public String getComments() { 312 return comments; 313 } 314 315 /** 316 * Returns a URL pointing to the media item as a String. This value can be passed to the constructor of 317 * the <code>javafx.scene.media.Media</code> class and thus used with the JavaFX media API. The URL has 318 * the custom scheme of <code>ipod-library</code>. For example, a URL might look like this: 319 * <br/> 320 * <code>ipod-library://item/item.m4a?id=12345</code> 321 * @return a URL pointing to the media item 322 */ 323 public String getURL() { 324 return url; 325 } 326 327 // setters have package access, will be set from native 328 void setMediaType(final MediaItemType mediaType) { 329 this.mediaType = mediaType; 330 } 331 332 // a convenience method to simplify the native code 333 void setMediaType(final int mediaType) { 334 this.mediaType = MediaItemType.fromIntValue(mediaType); 335 } 336 337 void setTitle(final String title) { 338 this.title = title; 339 } 340 341 void setAlbumTitle(final String albumTitle) { 342 this.albumTitle = albumTitle; 343 } 344 345 void setArtist(final String artist) { 346 this.artist = artist; 347 } 348 349 void setAlbumArtist(final String albumArtist) { 350 this.albumArtist = albumArtist; 351 } 352 353 void setGenre(final String genre) { 354 this.genre = genre; 355 } 356 357 void setComposer(final String composer) { 358 this.composer = composer; 359 } 360 361 void setPlaybackDuration(final Duration playbackDuration) { 362 this.playbackDuration = playbackDuration; 363 } 364 365 void setAlbumTrackNumber(final int albumTrackNumber) { 366 this.albumTrackNumber = albumTrackNumber; 367 } 368 369 void setAlbumTrackCount(final int albumTrackCount) { 370 this.albumTrackNumber = albumTrackCount; 371 } 372 373 void setDiscNumber(final int discNumber) { 374 this.discNumber = discNumber; 375 } 376 377 void setDiscCount(final int discCount) { 378 this.discCount = discCount; 379 } 380 381 void setLyrics(final String lyrics) { 382 this.lyrics = lyrics; 383 } 384 385 void setIsCompilation(final boolean isCompilation) { 386 this.isCompilation = isCompilation; 387 } 388 389 void setReleaseDate(final Calendar releaseDate) { 390 this.releaseDate = releaseDate; 391 } 392 393 void setBeatsPerMinute(final int beatsPerMinute) { 394 this.beatsPerMinute = beatsPerMinute; 395 } 396 397 void setComments(final String comments) { 398 this.comments = comments; 399 } 400 401 void setURL(final String url) { 402 this.url = url; 403 } 404 405 }