diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java index 831cf30..92aa912 100644 --- a/src/main/java/musicplayer/PlayerGUI.java +++ b/src/main/java/musicplayer/PlayerGUI.java @@ -503,15 +503,16 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf } private class GlobalKeyboardShortcuts extends GlobalKeyAdapter { - final int modifierKey = 93; - final int playPause = 116; - final int stop = 117; - final int previous = 118; - final int next = 119; + final int modifierKey = 164; + final int playPause = 192; + final int stop = 222; + final int previous = 219; + final int next = 221; boolean modified = false; @Override public void keyPressed(GlobalKeyEvent event) { + System.out.println(event.getVirtualKeyCode()); if(event.getVirtualKeyCode() == modifierKey) modified = true; else if(modified){ diff --git a/src/main/java/musicplayer/db/Gateway.java b/src/main/java/musicplayer/db/Gateway.java index d8403f4..12c4d0f 100644 --- a/src/main/java/musicplayer/db/Gateway.java +++ b/src/main/java/musicplayer/db/Gateway.java @@ -48,7 +48,7 @@ public class Gateway { public static Optional getOneSong(ExtractedMetadata metadata){ try (Session session = DatabaseManager.getInstance().getSession()) { Song song = (Song)session.createCriteria(Song.class) - .add(Restrictions.eq("songFile", metadata.songFile)).uniqueResult(); + .add(Restrictions.eq("songFile", metadata.getSongFile())).uniqueResult(); return (song == null) ? Optional.empty() : Optional.of(song); } } @@ -94,23 +94,23 @@ public class Gateway { public static void addSong(ExtractedMetadata metadata) { try (Session session = DatabaseManager.getInstance().getSession()) { session.beginTransaction(); - Optional albumObj = getOneAlbum(metadata.album); + Optional albumObj = getOneAlbum(metadata.getAlbum()); if (!albumObj.isPresent()) { - Album album = new Album(metadata.album, AlbumArtExtractor.getImageData(new File(metadata.songFile))); + Album album = new Album(metadata.getAlbum(), AlbumArtExtractor.getImageData(new File(metadata.getSongFile()))); albumObj = Optional.of(album); } - Optional artistObj = getOneArtist(metadata.artist); + Optional artistObj = getOneArtist(metadata.getArtist()); if (!artistObj.isPresent()) { - Artist artist = new Artist(metadata.artist); + Artist artist = new Artist(metadata.getArtist()); artistObj = Optional.of(artist); } Optional songObj = getOneSong(metadata); if(!songObj.isPresent()) - session.save(new Song(metadata.trackNumber, metadata.discNumber, metadata.title, artistObj.get(), - albumObj.get(), metadata.genre, metadata.songFile)); + session.save(new Song(metadata.getTrackNumber(), metadata.getDiscNumber(), metadata.getTitle(), artistObj.get(), + albumObj.get(), metadata.getGenre(), metadata.getSongFile())); else - songObj.get().updateData(metadata.trackNumber, metadata.discNumber, metadata.title, artistObj.get(), - albumObj.get(), metadata.genre, metadata.songFile); + songObj.get().updateData(metadata.getTrackNumber(), metadata.getDiscNumber(), metadata.getTitle(), artistObj.get(), + albumObj.get(), metadata.getGenre(), metadata.getSongFile()); session.getTransaction().commit(); } } diff --git a/src/main/java/musicplayer/model/ExtractedMetadata.java b/src/main/java/musicplayer/model/ExtractedMetadata.java index ca5350d..bdc1e0a 100644 --- a/src/main/java/musicplayer/model/ExtractedMetadata.java +++ b/src/main/java/musicplayer/model/ExtractedMetadata.java @@ -18,30 +18,32 @@ import java.util.Optional; * Internal class representing metadata extracted from a music file. */ public class ExtractedMetadata { - public final String title; - public final String album; - public final String artist; - public final String genre; - public final String songFile; - public final String trackNumber; - public final String discNumber; + private final Tag audioTags; + private String songFile; /** * @param audioTags jaudiotagger tag data. * @param songFile Location of the song file on the filesystem. */ public ExtractedMetadata(Tag audioTags, File songFile) { - this.trackNumber = audioTags.getFirst(FieldKey.TRACK); - this.title = audioTags.getFirst(FieldKey.TITLE); - this.album = audioTags.getFirst(FieldKey.ALBUM); - this.artist = audioTags.getFirst(FieldKey.ARTIST); - this.genre = audioTags.getFirst(FieldKey.GENRE); - this.discNumber = audioTags.getFirst(FieldKey.DISC_NO); + this.audioTags = audioTags; this.songFile = songFile.getAbsolutePath(); } + public String getTitle(){ return audioTags.getFirst(FieldKey.TITLE); } + + public String getArtist(){ return audioTags.getFirst(FieldKey.ARTIST); } + + public String getAlbum(){ return audioTags.getFirst(FieldKey.ALBUM); } + + public String getTrackNumber(){ return audioTags.getFirst(FieldKey.TRACK); } + + public String getGenre(){ return audioTags.getFirst(FieldKey.GENRE); } + + public String getDiscNumber(){ return audioTags.getFirst(FieldKey.DISC_NO); } + + public String getSongFile(){ return songFile; } + @Override - public String toString() { - return title + " - " + artist; - } + public String toString() { return getTitle()+ " - " + getArtist(); } } diff --git a/src/test/java/musicplayer/db/GatewayTest.java b/src/test/java/musicplayer/db/GatewayTest.java index 6441264..d001a25 100644 --- a/src/test/java/musicplayer/db/GatewayTest.java +++ b/src/test/java/musicplayer/db/GatewayTest.java @@ -153,11 +153,11 @@ public class GatewayTest { ExtractedMetadata metadata = new ExtractedMetadata(tags, new File("")); Gateway.addSong(metadata); Song song = (Song)session.createCriteria(Song.class).uniqueResult(); - assertEquals(song.getAlbum().getName(), metadata.album); - assertEquals(song.getArtist().getName(), metadata.artist); + assertEquals(song.getAlbum().getName(), metadata.getAlbum()); + assertEquals(song.getArtist().getName(), metadata.getArtist()); assertEquals(song.getTrackNumber(), Integer.valueOf(1)); - assertEquals(song.getTitle(), metadata.title); - assertEquals(song.getGenre(), metadata.genre); + assertEquals(song.getTitle(), metadata.getTitle()); + assertEquals(song.getGenre(), metadata.getGenre()); assertEquals(song.getDiscNumber(), Integer.valueOf(100)); } } \ No newline at end of file