Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package projekt;
- import javazoom.jl.player.Player;
- import java.io.FileInputStream;
- import entagged.audioformats.AudioFile;
- import entagged.audioformats.AudioFileIO;
- import entagged.audioformats.exceptions.CannotReadException;
- import java.io.File;
- import java.io.IOException;
- import java.util.*;
- import java.util.Map;
- public class Play {
- static Scanner scan = new Scanner(System.in);
- static CustomPlayer player = new CustomPlayer();
- public static void main(String[] cmdln) throws CannotReadException {
- printMenu();
- int choice = scan.nextInt();
- scan.nextLine();
- while (choice != 0) {
- dispatch(choice);
- printMenu();
- choice = scan.nextInt();
- scan.nextLine();
- }
- }
- public static void dispatch(int choice) throws CannotReadException {
- switch (choice) {
- case 0: {
- System.out.println("EXIT");
- System.exit(0);
- break;
- }
- case 1: {
- try {
- player.setPath("src/Elected.mp3");
- player.play(-1);
- } catch (Exception e) {
- System.out.println(e);
- }
- break;
- }
- case 2: {
- try {
- player.setPath("src/Elected.mp3");
- player.pause();
- } catch (Exception e) {
- System.out.println(e);
- }
- break;
- }
- case 3: {
- try {
- player.setPath("src/Elected.mp3");
- player.pause();
- } catch (Exception e) {
- System.out.println(e);
- }
- break;
- }
- case 4: {
- try{
- player.setPath("src/Elected.mp3");
- player.resume();
- } catch (Exception e){
- System.out.println(e);
- }
- break;
- }
- case 5: {
- break;
- }
- case 6: {
- break;
- }
- default:
- System.out.println("Sorry, invalid choice");
- }
- }
- // ----------------------------
- // Skriver ut användar meny
- // ----------------------------
- public static void printMenu() {
- System.out.println("\n Welcome");
- System.out.println(" ====");
- System.out.println("0: Exit");
- System.out.println("1: Play");
- System.out.println("2: Stop");
- System.out.println("3: Pause");
- System.out.println("4: Resume");
- System.out.println("5: Search for artist");
- System.out.print("\nEnter your choice: ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement