Advertisement
Guest User

bajs

a guest
Sep 18th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.06 KB | None | 0 0
  1. package projekt;
  2. import javazoom.jl.player.Player;
  3. import java.io.FileInputStream;
  4. import entagged.audioformats.AudioFile;
  5. import entagged.audioformats.AudioFileIO;
  6. import entagged.audioformats.exceptions.CannotReadException;
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.util.*;
  10. import java.util.Map;
  11.  
  12. public class Play {
  13.  
  14.     static Scanner scan = new Scanner(System.in);
  15.     static CustomPlayer player = new CustomPlayer();
  16.  
  17.     public static void main(String[] cmdln) throws CannotReadException {
  18.  
  19.         printMenu();
  20.         int choice = scan.nextInt();
  21.         scan.nextLine();
  22.  
  23.         while (choice != 0) {
  24.             dispatch(choice);
  25.             printMenu();
  26.             choice = scan.nextInt();
  27.             scan.nextLine();
  28.         }
  29.     }
  30.    
  31.    
  32.  
  33.     public static void dispatch(int choice) throws CannotReadException {
  34.         switch (choice) {
  35.             case 0: {
  36.                 System.out.println("EXIT");
  37.                 System.exit(0);
  38.                 break;
  39.             }
  40.             case 1: {
  41.  
  42.                 try {
  43.                     player.setPath("src/Elected.mp3");
  44.                     player.play(-1);
  45.                 } catch (Exception e) {
  46.                     System.out.println(e);
  47.                 }
  48.  
  49.                 break;
  50.             }
  51.             case 2: {
  52.  
  53.                 try {
  54.                     player.setPath("src/Elected.mp3");
  55.                     player.pause();
  56.                 } catch (Exception e) {
  57.                     System.out.println(e);
  58.                 }
  59.  
  60.                 break;
  61.             }
  62.             case 3: {
  63.                
  64.                
  65.                 try {
  66.                            player.setPath("src/Elected.mp3");
  67.                        player.pause();
  68.                    } catch (Exception e) {
  69.                        System.out.println(e);
  70.                    
  71.                 }
  72.  
  73.                 break;
  74.             }
  75.  
  76.             case 4: {
  77.                 try{
  78.                         player.setPath("src/Elected.mp3");
  79.                         player.resume();
  80.                 }       catch (Exception e){
  81.                         System.out.println(e);
  82.                
  83.                 }
  84.                
  85.                
  86.                 break;
  87.             }
  88.             case 5: {
  89.                 break;
  90.             }
  91.  
  92.             case 6: {
  93.                 break;
  94.             }
  95.  
  96.             default:
  97.                 System.out.println("Sorry, invalid choice");
  98.         }
  99.     }
  100.  
  101.     // ----------------------------
  102.     // Skriver ut användar meny
  103.     // ----------------------------
  104.     public static void printMenu() {
  105.         System.out.println("\n  Welcome");
  106.         System.out.println("   ====");
  107.         System.out.println("0: Exit");
  108.         System.out.println("1: Play");
  109.         System.out.println("2: Stop");
  110.         System.out.println("3: Pause");
  111.         System.out.println("4: Resume");
  112.         System.out.println("5: Search for artist");
  113.         System.out.print("\nEnter your choice: ");
  114.     }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement