From e58b48a3162539cb79ff495d6040ca6f53f069d6 Mon Sep 17 00:00:00 2001 From: said belhadj Date: Sat, 26 Jun 2021 01:58:15 +0200 Subject: Add the possibility to listen a song thanks to Audio System library --- src/musichub/business/AudioElement.java | 16 ++++++++++++++++ src/musichub/business/MusicHub.java | 13 +++++++++++++ src/musichub/business/Song.java | 11 +++++++++++ src/musichub/main/Main.java | 11 ++++++++++- 4 files changed, 50 insertions(+), 1 deletion(-) (limited to 'src/musichub') diff --git a/src/musichub/business/AudioElement.java b/src/musichub/business/AudioElement.java index e0a686b..9294b49 100644 --- a/src/musichub/business/AudioElement.java +++ b/src/musichub/business/AudioElement.java @@ -3,8 +3,16 @@ package musichub.business; import org.w3c.dom.Document; import org.w3c.dom.Element; +import java.io.File; +import java.io.IOException; import java.util.UUID; +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; + public abstract class AudioElement { protected String title; protected String artist; @@ -84,5 +92,13 @@ public abstract class AudioElement { parentElement.appendChild(contentElement); } + + public void playSong() throws UnsupportedAudioFileException, IOException, LineUnavailableException { + File file = new File(this.content); + AudioInputStream audioStream = AudioSystem.getAudioInputStream(file); + Clip clip = AudioSystem.getClip(); + clip.open(audioStream); + clip.start(); + } } \ No newline at end of file diff --git a/src/musichub/business/MusicHub.java b/src/musichub/business/MusicHub.java index 38e2214..e138d84 100644 --- a/src/musichub/business/MusicHub.java +++ b/src/musichub/business/MusicHub.java @@ -6,8 +6,12 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import java.io.IOException; import java.util.*; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; + class SortByDate implements Comparator { public int compare(Album a1, Album a2) { return a1.getDate().compareTo(a2.getDate()); @@ -326,4 +330,13 @@ public class MusicHub { } xmlHandler.createXMLFile(document, ELEMENTS_FILE_PATH); } + + public void getSong(List Songs, String songTitle) throws NoAlbumFoundException, UnsupportedAudioFileException, IOException, LineUnavailableException { + for (AudioElement s : Songs) { + if (s.getTitle().equalsIgnoreCase(songTitle)) { + s.playSong(); + } + } + + } } \ No newline at end of file diff --git a/src/musichub/business/Song.java b/src/musichub/business/Song.java index 3e9011b..7b90156 100644 --- a/src/musichub/business/Song.java +++ b/src/musichub/business/Song.java @@ -1,5 +1,14 @@ package musichub.business; +import java.io.File; +import java.io.IOException; + +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; + import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -53,4 +62,6 @@ public class Song extends AudioElement { parentElement.appendChild(song); } + + } \ No newline at end of file diff --git a/src/musichub/main/Main.java b/src/musichub/main/Main.java index b72a95b..58080bd 100644 --- a/src/musichub/main/Main.java +++ b/src/musichub/main/Main.java @@ -2,11 +2,17 @@ package musichub.main; import musichub.business.*; +import java.io.IOException; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Scanner; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; + public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws UnsupportedAudioFileException, IOException, LineUnavailableException { MusicHub theHub = new MusicHub(); @@ -55,7 +61,10 @@ public class Main { albumTitle = scan.nextLine(); try { + List songs = theHub.getAlbumSongs(albumTitle); System.out.println(theHub.getAlbumSongs(albumTitle)); + String song = scan.nextLine(); + theHub.getSong(songs, song); } catch (NoAlbumFoundException ex) { System.out.println("No album found with the requested title " + ex.getMessage()); } -- cgit v1.2.3 From 05b5bb7d2407006e08f46f66893a972a9f091952 Mon Sep 17 00:00:00 2001 From: said belhadj Date: Sat, 26 Jun 2021 12:01:49 +0200 Subject: Add reset, pause, quit functionality --- .classpath | 6 ++++ .idea/.gitignore | 8 ++++++ .idea/misc.xml | 6 ++++ .idea/modules.xml | 8 ++++++ .idea/vcs.xml | 6 ++++ .project | 17 +++++++++++ bin/.gitignore | 1 + bin/musichub/business/Album.class | Bin 4580 -> 5577 bytes bin/musichub/business/AudioBook.class | Bin 3854 -> 3968 bytes bin/musichub/business/AudioElement.class | Bin 3209 -> 5105 bytes bin/musichub/business/Category.class | Bin 1318 -> 1442 bytes bin/musichub/business/Genre.class | Bin 1329 -> 1453 bytes bin/musichub/business/Language.class | Bin 1316 -> 1440 bytes bin/musichub/business/MusicHub.class | Bin 8924 -> 11575 bytes bin/musichub/business/NoAlbumFoundException.class | Bin 260 -> 387 bytes .../business/NoElementFoundException.class | Bin 264 -> 393 bytes .../business/NoPlayListFoundException.class | Bin 266 -> 396 bytes bin/musichub/business/PlayList.class | Bin 3240 -> 3905 bytes bin/musichub/business/Song.class | Bin 2853 -> 2907 bytes bin/musichub/business/SortByAuthor.class | Bin 719 -> 891 bytes bin/musichub/business/SortByDate.class | Bin 681 -> 844 bytes bin/musichub/business/SortByGenre.class | Bin 685 -> 848 bytes bin/musichub/main/Main.class | Bin 7826 -> 9528 bytes bin/musichub/util/XMLHandler.class | Bin 2388 -> 2909 bytes .../spoteezer/musichub/business/Album.class | Bin 0 -> 5606 bytes .../spoteezer/musichub/business/AudioBook.class | Bin 0 -> 4278 bytes .../spoteezer/musichub/business/AudioElement.class | Bin 0 -> 3752 bytes .../spoteezer/musichub/business/Category.class | Bin 0 -> 1476 bytes .../spoteezer/musichub/business/Genre.class | Bin 0 -> 1487 bytes .../spoteezer/musichub/business/Language.class | Bin 0 -> 1474 bytes .../spoteezer/musichub/business/MusicHub.class | Bin 0 -> 11031 bytes .../musichub/business/NoAlbumFoundException.class | Bin 0 -> 387 bytes .../business/NoElementFoundException.class | Bin 0 -> 393 bytes .../business/NoPlayListFoundException.class | Bin 0 -> 396 bytes .../spoteezer/musichub/business/PlayList.class | Bin 0 -> 3926 bytes .../spoteezer/musichub/business/Song.class | Bin 0 -> 3217 bytes .../spoteezer/musichub/business/SortByAuthor.class | Bin 0 -> 901 bytes .../spoteezer/musichub/business/SortByDate.class | Bin 0 -> 854 bytes .../spoteezer/musichub/business/SortByGenre.class | Bin 0 -> 858 bytes out/production/spoteezer/musichub/main/Main.class | Bin 0 -> 9322 bytes .../spoteezer/musichub/util/XMLHandler.class | Bin 0 -> 2921 bytes spoteezer.iml | 11 +++++++ src/musichub/business/AudioElement.java | 32 +++++++++++++++++++-- src/musichub/business/MusicHub.java | 8 +++--- src/musichub/business/Song.java | 9 ------ src/musichub/main/Main.java | 6 ++-- 46 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 .classpath create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .project create mode 100644 bin/.gitignore create mode 100644 out/production/spoteezer/musichub/business/Album.class create mode 100644 out/production/spoteezer/musichub/business/AudioBook.class create mode 100644 out/production/spoteezer/musichub/business/AudioElement.class create mode 100644 out/production/spoteezer/musichub/business/Category.class create mode 100644 out/production/spoteezer/musichub/business/Genre.class create mode 100644 out/production/spoteezer/musichub/business/Language.class create mode 100644 out/production/spoteezer/musichub/business/MusicHub.class create mode 100644 out/production/spoteezer/musichub/business/NoAlbumFoundException.class create mode 100644 out/production/spoteezer/musichub/business/NoElementFoundException.class create mode 100644 out/production/spoteezer/musichub/business/NoPlayListFoundException.class create mode 100644 out/production/spoteezer/musichub/business/PlayList.class create mode 100644 out/production/spoteezer/musichub/business/Song.class create mode 100644 out/production/spoteezer/musichub/business/SortByAuthor.class create mode 100644 out/production/spoteezer/musichub/business/SortByDate.class create mode 100644 out/production/spoteezer/musichub/business/SortByGenre.class create mode 100644 out/production/spoteezer/musichub/main/Main.class create mode 100644 out/production/spoteezer/musichub/util/XMLHandler.class create mode 100644 spoteezer.iml (limited to 'src/musichub') diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..0cbf9cd --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..644a944 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8f05ee9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..cf232f0 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + spoteezer + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..0076c39 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/musichub/ diff --git a/bin/musichub/business/Album.class b/bin/musichub/business/Album.class index 0bc7b94..e2e5b03 100644 Binary files a/bin/musichub/business/Album.class and b/bin/musichub/business/Album.class differ diff --git a/bin/musichub/business/AudioBook.class b/bin/musichub/business/AudioBook.class index acd92fc..6ab9f2a 100644 Binary files a/bin/musichub/business/AudioBook.class and b/bin/musichub/business/AudioBook.class differ diff --git a/bin/musichub/business/AudioElement.class b/bin/musichub/business/AudioElement.class index b737756..9f6e12a 100644 Binary files a/bin/musichub/business/AudioElement.class and b/bin/musichub/business/AudioElement.class differ diff --git a/bin/musichub/business/Category.class b/bin/musichub/business/Category.class index 08b0990..85ff126 100644 Binary files a/bin/musichub/business/Category.class and b/bin/musichub/business/Category.class differ diff --git a/bin/musichub/business/Genre.class b/bin/musichub/business/Genre.class index 5a59007..db6f5d7 100644 Binary files a/bin/musichub/business/Genre.class and b/bin/musichub/business/Genre.class differ diff --git a/bin/musichub/business/Language.class b/bin/musichub/business/Language.class index e22490e..dd87891 100644 Binary files a/bin/musichub/business/Language.class and b/bin/musichub/business/Language.class differ diff --git a/bin/musichub/business/MusicHub.class b/bin/musichub/business/MusicHub.class index 0a7ffda..40e09b2 100644 Binary files a/bin/musichub/business/MusicHub.class and b/bin/musichub/business/MusicHub.class differ diff --git a/bin/musichub/business/NoAlbumFoundException.class b/bin/musichub/business/NoAlbumFoundException.class index 2c37b0c..7cee1f4 100644 Binary files a/bin/musichub/business/NoAlbumFoundException.class and b/bin/musichub/business/NoAlbumFoundException.class differ diff --git a/bin/musichub/business/NoElementFoundException.class b/bin/musichub/business/NoElementFoundException.class index 6afa6b4..e8118b9 100644 Binary files a/bin/musichub/business/NoElementFoundException.class and b/bin/musichub/business/NoElementFoundException.class differ diff --git a/bin/musichub/business/NoPlayListFoundException.class b/bin/musichub/business/NoPlayListFoundException.class index 2290022..15a3811 100644 Binary files a/bin/musichub/business/NoPlayListFoundException.class and b/bin/musichub/business/NoPlayListFoundException.class differ diff --git a/bin/musichub/business/PlayList.class b/bin/musichub/business/PlayList.class index 571eac0..9403ae5 100644 Binary files a/bin/musichub/business/PlayList.class and b/bin/musichub/business/PlayList.class differ diff --git a/bin/musichub/business/Song.class b/bin/musichub/business/Song.class index 2cad917..7790568 100644 Binary files a/bin/musichub/business/Song.class and b/bin/musichub/business/Song.class differ diff --git a/bin/musichub/business/SortByAuthor.class b/bin/musichub/business/SortByAuthor.class index 009d9fe..232d4a1 100644 Binary files a/bin/musichub/business/SortByAuthor.class and b/bin/musichub/business/SortByAuthor.class differ diff --git a/bin/musichub/business/SortByDate.class b/bin/musichub/business/SortByDate.class index 4ad6b49..68e775b 100644 Binary files a/bin/musichub/business/SortByDate.class and b/bin/musichub/business/SortByDate.class differ diff --git a/bin/musichub/business/SortByGenre.class b/bin/musichub/business/SortByGenre.class index cf0f29c..78295f9 100644 Binary files a/bin/musichub/business/SortByGenre.class and b/bin/musichub/business/SortByGenre.class differ diff --git a/bin/musichub/main/Main.class b/bin/musichub/main/Main.class index 0ebef6e..9528e6f 100644 Binary files a/bin/musichub/main/Main.class and b/bin/musichub/main/Main.class differ diff --git a/bin/musichub/util/XMLHandler.class b/bin/musichub/util/XMLHandler.class index 9a53fc4..04ba597 100644 Binary files a/bin/musichub/util/XMLHandler.class and b/bin/musichub/util/XMLHandler.class differ diff --git a/out/production/spoteezer/musichub/business/Album.class b/out/production/spoteezer/musichub/business/Album.class new file mode 100644 index 0000000..c08b1be Binary files /dev/null and b/out/production/spoteezer/musichub/business/Album.class differ diff --git a/out/production/spoteezer/musichub/business/AudioBook.class b/out/production/spoteezer/musichub/business/AudioBook.class new file mode 100644 index 0000000..3ad965d Binary files /dev/null and b/out/production/spoteezer/musichub/business/AudioBook.class differ diff --git a/out/production/spoteezer/musichub/business/AudioElement.class b/out/production/spoteezer/musichub/business/AudioElement.class new file mode 100644 index 0000000..ab20d50 Binary files /dev/null and b/out/production/spoteezer/musichub/business/AudioElement.class differ diff --git a/out/production/spoteezer/musichub/business/Category.class b/out/production/spoteezer/musichub/business/Category.class new file mode 100644 index 0000000..51a68d1 Binary files /dev/null and b/out/production/spoteezer/musichub/business/Category.class differ diff --git a/out/production/spoteezer/musichub/business/Genre.class b/out/production/spoteezer/musichub/business/Genre.class new file mode 100644 index 0000000..66a7d69 Binary files /dev/null and b/out/production/spoteezer/musichub/business/Genre.class differ diff --git a/out/production/spoteezer/musichub/business/Language.class b/out/production/spoteezer/musichub/business/Language.class new file mode 100644 index 0000000..31b17c2 Binary files /dev/null and b/out/production/spoteezer/musichub/business/Language.class differ diff --git a/out/production/spoteezer/musichub/business/MusicHub.class b/out/production/spoteezer/musichub/business/MusicHub.class new file mode 100644 index 0000000..e1a0961 Binary files /dev/null and b/out/production/spoteezer/musichub/business/MusicHub.class differ diff --git a/out/production/spoteezer/musichub/business/NoAlbumFoundException.class b/out/production/spoteezer/musichub/business/NoAlbumFoundException.class new file mode 100644 index 0000000..03aff87 Binary files /dev/null and b/out/production/spoteezer/musichub/business/NoAlbumFoundException.class differ diff --git a/out/production/spoteezer/musichub/business/NoElementFoundException.class b/out/production/spoteezer/musichub/business/NoElementFoundException.class new file mode 100644 index 0000000..6ba1c87 Binary files /dev/null and b/out/production/spoteezer/musichub/business/NoElementFoundException.class differ diff --git a/out/production/spoteezer/musichub/business/NoPlayListFoundException.class b/out/production/spoteezer/musichub/business/NoPlayListFoundException.class new file mode 100644 index 0000000..54319de Binary files /dev/null and b/out/production/spoteezer/musichub/business/NoPlayListFoundException.class differ diff --git a/out/production/spoteezer/musichub/business/PlayList.class b/out/production/spoteezer/musichub/business/PlayList.class new file mode 100644 index 0000000..ea68021 Binary files /dev/null and b/out/production/spoteezer/musichub/business/PlayList.class differ diff --git a/out/production/spoteezer/musichub/business/Song.class b/out/production/spoteezer/musichub/business/Song.class new file mode 100644 index 0000000..c3bdeb7 Binary files /dev/null and b/out/production/spoteezer/musichub/business/Song.class differ diff --git a/out/production/spoteezer/musichub/business/SortByAuthor.class b/out/production/spoteezer/musichub/business/SortByAuthor.class new file mode 100644 index 0000000..fb8ee7a Binary files /dev/null and b/out/production/spoteezer/musichub/business/SortByAuthor.class differ diff --git a/out/production/spoteezer/musichub/business/SortByDate.class b/out/production/spoteezer/musichub/business/SortByDate.class new file mode 100644 index 0000000..c52e870 Binary files /dev/null and b/out/production/spoteezer/musichub/business/SortByDate.class differ diff --git a/out/production/spoteezer/musichub/business/SortByGenre.class b/out/production/spoteezer/musichub/business/SortByGenre.class new file mode 100644 index 0000000..2016012 Binary files /dev/null and b/out/production/spoteezer/musichub/business/SortByGenre.class differ diff --git a/out/production/spoteezer/musichub/main/Main.class b/out/production/spoteezer/musichub/main/Main.class new file mode 100644 index 0000000..419fb9c Binary files /dev/null and b/out/production/spoteezer/musichub/main/Main.class differ diff --git a/out/production/spoteezer/musichub/util/XMLHandler.class b/out/production/spoteezer/musichub/util/XMLHandler.class new file mode 100644 index 0000000..4ab0064 Binary files /dev/null and b/out/production/spoteezer/musichub/util/XMLHandler.class differ diff --git a/spoteezer.iml b/spoteezer.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/spoteezer.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/musichub/business/AudioElement.java b/src/musichub/business/AudioElement.java index 9294b49..0c1e9e4 100644 --- a/src/musichub/business/AudioElement.java +++ b/src/musichub/business/AudioElement.java @@ -5,6 +5,7 @@ import org.w3c.dom.Element; import java.io.File; import java.io.IOException; +import java.util.Scanner; import java.util.UUID; import javax.sound.sampled.AudioInputStream; @@ -93,12 +94,39 @@ public abstract class AudioElement { } - public void playSong() throws UnsupportedAudioFileException, IOException, LineUnavailableException { + public void manageAudioElement() throws UnsupportedAudioFileException, IOException, LineUnavailableException { + + Scanner scanner = new Scanner(System.in); + File file = new File(this.content); AudioInputStream audioStream = AudioSystem.getAudioInputStream(file); Clip clip = AudioSystem.getClip(); clip.open(audioStream); - clip.start(); + + String action = ""; + + while(!action.equals("Q")) { + System.out.println("P = Play \b S = Stop \b R = Reset \b Q = Quit"); + System.out.println("Enter your choice"); + action = scanner.next(); + action = action.toUpperCase(); + + switch(action) { + case "S" : clip.stop(); + break; + case "P" : clip.start(); + break; + case "R" : clip.setMicrosecondPosition(0); + break; + case "Q" : clip.stop(); + break; + default : System.out.println("try again"); + } + System.out.println("You stoped the Audio element"); + } + + clip.close(); + } } \ No newline at end of file diff --git a/src/musichub/business/MusicHub.java b/src/musichub/business/MusicHub.java index e138d84..f7cf137 100644 --- a/src/musichub/business/MusicHub.java +++ b/src/musichub/business/MusicHub.java @@ -331,10 +331,10 @@ public class MusicHub { xmlHandler.createXMLFile(document, ELEMENTS_FILE_PATH); } - public void getSong(List Songs, String songTitle) throws NoAlbumFoundException, UnsupportedAudioFileException, IOException, LineUnavailableException { - for (AudioElement s : Songs) { - if (s.getTitle().equalsIgnoreCase(songTitle)) { - s.playSong(); + public void getAudioElement(List audios, String elementTitle) throws NoAlbumFoundException, UnsupportedAudioFileException, IOException, LineUnavailableException { + for (AudioElement el : audios) { + if (el.getTitle().equalsIgnoreCase(elementTitle)) { + el.manageAudioElement(); } } diff --git a/src/musichub/business/Song.java b/src/musichub/business/Song.java index 7b90156..564b7c5 100644 --- a/src/musichub/business/Song.java +++ b/src/musichub/business/Song.java @@ -1,14 +1,5 @@ package musichub.business; -import java.io.File; -import java.io.IOException; - -import javax.sound.sampled.AudioInputStream; -import javax.sound.sampled.AudioSystem; -import javax.sound.sampled.Clip; -import javax.sound.sampled.LineUnavailableException; -import javax.sound.sampled.UnsupportedAudioFileException; - import org.w3c.dom.Document; import org.w3c.dom.Element; diff --git a/src/musichub/main/Main.java b/src/musichub/main/Main.java index 58080bd..2876734 100644 --- a/src/musichub/main/Main.java +++ b/src/musichub/main/Main.java @@ -3,7 +3,6 @@ package musichub.main; import musichub.business.*; import java.io.IOException; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Scanner; @@ -47,7 +46,8 @@ public class Main { albumTitle = scan.nextLine(); try { - System.out.println(theHub.getAlbumSongsSortedByGenre(albumTitle)); + List songs = theHub.getAlbumSongsSortedByGenre(albumTitle); + System.out.println(songs);; } catch (NoAlbumFoundException ex) { System.out.println("No album found with the requested title " + ex.getMessage()); } @@ -64,7 +64,7 @@ public class Main { List songs = theHub.getAlbumSongs(albumTitle); System.out.println(theHub.getAlbumSongs(albumTitle)); String song = scan.nextLine(); - theHub.getSong(songs, song); + theHub.getAudioElement(songs, song); } catch (NoAlbumFoundException ex) { System.out.println("No album found with the requested title " + ex.getMessage()); } -- cgit v1.2.3