I have created a playlist class that ask the user to enter a song name and etc. What I want to do is have the mp3 class plays the song that the user has entered, but I don't know how. Any suggestions? Thanks in advance!
Here are my codes:
import java.util.Scanner; public class PlaylistDriver {//Start of class public static Playlist list; public static void main(String[] args) {//Start of main list = new Playlist(); while(true) { menu(); processInput(); } } public static void processInput() {//Start of Process Input Scanner keyboard = new Scanner(System.in); String input = keyboard.nextLine().toLowerCase(); switch(input.charAt(0)) {//Start of switch case 'a': addSong(); break; case 'i': printSongByIndex(); break; case 'n': removeSongByName(); break; case 'p': printSongs(); break; case 's': getSize(); break; case 't': getTotalTime(); break; case 'f': getFormattedTime(); break; case 'c': clearSongs(); break; case 'q': System.exit(0); break; default: System.out.println("..........."); }//End of switch }//End of Process Input public static void addSong() {//Add Song Scanner keyboard = new Scanner(System.in); System.out.print("Please enter a song name: "); String name = keyboard.nextLine(); System.out.print("Please enter song artist: "); String artist = keyboard.nextLine(); System.out.print("Please enter an album: "); String album = keyboard.nextLine(); System.out.print("Please enter genre: "); String genre = keyboard.nextLine(); System.out.print("Please enter length of song: "); double length = keyboard.nextDouble(); Song information = new Song(name, artist, album, length, genre); list.add(information); }//End of Add Song public static void printSongs() {//Print Song Information System.out.println(list); }//End of Print Song Information public static void printSongByIndex() {//Print all songs System.out.println("Please enter index of song to view: "); Scanner keyboard = new Scanner(System.in); int information = keyboard.nextInt(); System.out.print(list.get(information)); } public static void removeSongByName() {//To remove song System.out.print("\nPlease enter the name of the song to remove: "); Scanner keyboard = new Scanner(System.in); String name = keyboard.nextLine(); list.remove( name ); }//End of remove song public static void getSize() {//Get size of song System.out.println("\nTotal number of songs: " + list.size()); } public static void getTotalTime() {//Get Total Time System.out.println("Total Time: " + list.totalTime()); } public static void getFormattedTime() {//Get formatted time System.out.println("Total Formatted Time:" + list.formattedTotalTime()); } public static void clearSongs() {//Clear Songs list.clear(); } public static void menu() {//Print Menu System.out.println("--------MP3 PLAYLIST--------"); System.out.println("[A]dd a Song"); System.out.println("[P]rint songs"); System.out.println("Pr[i]nt song by index"); System.out.println("Remove song by [n]ame"); System.out.println("Get total [s]ize"); System.out.println("Get total [t]ime"); System.out.println("Get [f]ormatted time"); System.out.println("[C]lear all songs"); System.out.println("[Q]uit"); } }//End of class
import javax.swing.JButton; import javax.swing.JFrame; import java.awt.event.ActionListener; import java.awt.*; import java.awt.event.*; import java.io.FileInputStream; import java.io.BufferedInputStream; import javazoom.jl.player.advanced.AdvancedPlayer; public class MP3PLAYER {//Start of class private AdvancedPlayer player; public static void main(String[] args) { new MP3PLAYER().SETUP(); } public void SETUP() { JFrame frame = new JFrame("MP3 PLAYER"); frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton btnplay = new JButton("Play"); JButton btnstop = new JButton("Stop"); btnplay.addActionListener(new playMusicListener()); btnstop.addActionListener(new stopMusicListener()); frame.getContentPane().add(BorderLayout.WEST, btnplay); frame.getContentPane().add(BorderLayout.EAST, btnstop); frame.setVisible(true); } public class playMusicListener implements ActionListener { public void actionPerformed(ActionEvent a) { try { FileInputStream file = new FileInputStream("mp3 goes here"); player = new AdvancedPlayer(file); player.play(); } catch(Exception e) { System.out.println(e); } } } public class stopMusicListener implements ActionListener { public void actionPerformed(ActionEvent a) { try { FileInputStream file = new FileInputStream(""); player = new AdvancedPlayer(file); player.stop(); } catch(Exception ex) { System.out.println(ex); } } } }//End of class