IITTrackCollection selectedTracks = iTunes.getSelectedTracks();
if (selectedTracks == null) {
System.out.println("No tracks selected!");
} else {
IITUserPlaylist newPlaylist = iTunes.createPlaylist(
"SelectedTracks").getUserPlaylist();
boolean hasNext = true;
int i = 1;
while (hasNext) {
IITTrack track = selectedTracks.item(i);
if (track == null) {
hasNext = false;
} else {
System.out.println(track.getName() + " by "
+ track.getArtist() + " added to playlist.");
newPlaylist.addTrack(track);
i++;
}
}
double sizeMB = newPlaylist.getSize() / 1000000;
String duration = newPlaylist.getTime();
String name = newPlaylist.getName();
System.out.println("Playlist \"" + name
+ "\" created. \nSize of the playlist: " + sizeMB
+ "MB. \nDuration of playlist: " + duration);
}