์ค๋น๋ฌผ : jarํ์ผ
Musicํด๋์ค (ํ๋๊ฐ, ๋ฉ์๋)
package ex03๋ฎค์งํ๋ ์ด์ด;
public class Music {
// ์๋ฃํ
// 1. ํ๋(์์ฑ, ๋ฐ์ดํฐ)
private String title; // ๋
ธ๋์ ๋ชฉ
private String singer; // ๊ฐ์
private String path; // ๋
ธ๋์ ์ฅ๊ฒฝ๋ก
// 2. ๋ฉ์๋(๋ก์ง, ํ์)
//์์ฑ์
public Music(String title, String singer, String path) {
this.title = title;
this.singer = singer;
this.path = path;
}
//getter์์ฑ
public String getTitle() {
return title;
}
public String getSinger() {
return singer;
}
public String getPath() {
return path;
}
}
MusicMain ํด๋์ค (์ฌ์ฉ์ ํ๋ฉด)
package ex03๋ฎค์งํ๋ ์ด์ด;
import java.util.ArrayList;
import java.util.Scanner;
import javazoom.jl.player.MP3Player;
public class MusicMain {
public static void main(String[] args) {
// ๋
ธ๋๋ค์ ๊ณตํต๊ฒฝ๋ก
String comPath = "C:\\Users\\USER\\Desktop\\JavaStudy\\ex0706\\src\\player\\";
// jar(ํด๋์คํ์ผ๋ค์ ์งํฉ) ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ
// ํ๋ก์ ํธ ์ ํ --> ๋ง์ฐ์ค ์ฐํด๋ฆญ --> build path
// --> configure build path --> ํญ์ค์ libraries
// --> class path ์ต์
์ ํ --> add jars
// 1. MP3Player ์ฌ์ฉํด๋ณด๊ธฐ!!!!!!!!!
// --> ๋ค๋ฅธ ์ฌ๋์ด ๋ง๋ ์๋ฃํ(ํด๋์ค)
MP3Player mp3 = new MP3Player();
// 2. Music ์๋ฃํ์ ์ ์ฅํ ์ ์๋ ๊ฐ๋ณ๋ฐฐ์ด musicList์์ฑ
ArrayList<Music> musicList = new ArrayList<Music>();
// 3. musicList 5๊ฐ ๋ฐ์ดํฐ ์ถ๊ฐํ๊ธฐ
// Music m = new Music("Attention", "๋ด์ง์ค", comPath+"Attention.mp3");
// musicList.add(m);
musicList.add(new Music("Attention", "๋ด์ง์ค", comPath + "Attention.mp3"));
musicList.add(new Music("Butterfly", "์ ์ํธ", comPath + "Butterfly.mp3"));
musicList.add(new Music("LoveDive", "์์ด๋ธ", comPath + "Lovedive.mp3"));
musicList.add(new Music("Nxde", "์์ด๋ค", comPath + "Nxde.mp3"));
musicList.add(new Music("RushHour", "ํฌ๋ฌ์ฌ", comPath + "Rushhour.mp3"));
Scanner sc = new Scanner(System.in);
// ํ์ฌ ์ฌ์์ค์ธ ๋
ธ๋ ์ธ๋ฑ์ค ๋ฒํธ
int index = 0;
while (true) {
System.out.print("[1]๋
ธ๋์ฌ์ [2]๋ค์๊ณก [3]์ด์ ๊ณก [4]์ ์ง [5]์ข
๋ฃ >> ");
int input = sc.nextInt();
if (input == 1) {
// ๋
ธ๋์ฌ์
// (0) ํ์ฌ ์ฌ์์ค์ด๋ผ๋ฉด ํ๋ฒ ๋ฉ์ถ๊ธฐ
if (mp3.isPlaying()) {
mp3.stop();
}
// (1) musicList์ ์ฒซ๋ฒ์งธ ๋
ธ๋ ์ฌ์
mp3.play(musicList.get(index).getPath());
// (2) ๋
ธ๋์ ๋ํ ์ ๋ณด๋ฅผ ์ถ๋ ฅ
System.out.println("====์ฌ์์ค์ธ ๋
ธ๋====");
System.out.println("๋
ธ๋ ์ ๋ชฉ \t ๊ฐ์");
System.out.print(musicList.get(index).getTitle() + " \t ");
System.out.println(musicList.get(index).getSinger());
} else if (input == 2) {
// ๋ค์๊ณก
// ๋ค์๊ณก์ด ์์์ ๊ฒฝ์ฐ์๋ง index 1์ฆ๊ฐ์ํค๊ณ ๋
ธ๋๋ฅผ ์ฌ์
if (index < musicList.size() - 1) {
index++;
// (0) ๋
ธ๋๊ฐ ์ฌ์์ค์ด๋ผ๋ฉด ์ฌ์์ค์ธ ๋
ธ๋ ๋ฉ์ถ๊ธฐ
if (mp3.isPlaying()) {
mp3.stop();
}
// (1) musicList ๋๋ฒ์งธ ๋ฐฉ์ ์๋ ๋
ธ๋ ์ฌ์
mp3.play(musicList.get(index).getPath());
// (2) musicList ๋๋ฒ์งธ ๋ฐฉ์ ์๋ ๋
ธ๋ ์ ๋ณด ์ถ๋ ฅ
System.out.println("====์ฌ์์ค์ธ ๋
ธ๋====");
System.out.println("๋
ธ๋ ์ ๋ชฉ \t ๊ฐ์");
System.out.print(musicList.get(index).getTitle() + " \t ");
System.out.println(musicList.get(index).getSinger());
}else {
System.out.println("๋ค์๊ณก์ด ์์ต๋๋ค.");
if(mp3.isPlaying()) {
mp3.stop();
}
}
} else if (input == 3) {
// ์ด์ ๊ณก
if(index > 0) {
index--;
if(mp3.isPlaying()) {
mp3.stop();
}
mp3.play(musicList.get(index).getPath());
System.out.println("====์ฌ์์ค์ธ ๋
ธ๋====");
System.out.println("๋
ธ๋ ์ ๋ชฉ \t ๊ฐ์");
System.out.print(musicList.get(index).getTitle() + " \t ");
System.out.println(musicList.get(index).getSinger());
}else {
System.out.println("์ด์ ๊ณก์ด ์์ต๋๋ค.");
if(mp3.isPlaying()) {
mp3.stop();
}
}
} else if (input == 4) {
// ์ ์ง
if (mp3.isPlaying()) {
mp3.stop();
}
System.out.println("๋
ธ๋๋ฅผ ์ ์งํฉ๋๋ค.");
} else if (input == 5) {
if (mp3.isPlaying()) {
mp3.stop();
}
System.out.println("ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํฉ๋๋ค.");
break;
}
}
}
}