-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdapter.java
More file actions
76 lines (64 loc) · 1.58 KB
/
Adapter.java
File metadata and controls
76 lines (64 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
interface MediaPlayer {
void play(String audioType, Stirng fileName);
}
interface AdvancedMediaPlayer {
void playVlc(String fileName);
void playCD(String fileName);
}
class VlcPlayer implements AdvancedMediaPlayer {
void playVlc(Stirng fileName) {
System.out.println("Playing Vlc " + fileName);
}
void playCD(String fileName) {
}
}
class CDPlayer implements AdvancedMediaPlayer {
void playVlc(String fileName) {
}
void playCD(String fileName) {
System.out.println("Playing CD " + fileName);
}
}
class MediaAdapter implements MediaPlayer {
AdvancedMediaPlayer player;
void setPlayer(String audioType) {
if (audioType.equalsIgnoreCase("Vlc")) {
player = new VlcPlayer();
}
else if (audioType.equalsIgnoreCase("CD")) {
player = new CDPlayer();
}
}
void play(String audioType, String fileName) {
if (audioType.equalsIgnoreCase("Vlc")) {
player.playVlc(fileName);
}
else if (audioType.equalsIgnoreCase("CD")) {
player.playCD(fileName);
}
}
}
class AudioPlayer implements MediaPlayer {
MediaAdapter adapter;
void play(String audioType, String fileName) {
if (audioType.equalsIgnoreCase("mp3")) {
System.out.println("Playing MP3 " + fileName);
}
else if (audioType.equalsIgnoreCase("Vlc") || audioType.equalsIgnoreCase("CD")) {
adapter = new MediaAdapter();
adapter.play(audioType, fileName);
}
else {
System.out.println("Not supported!");
}
}
}
class Test {
public static void main(String[] args) {
AudioPlayer ap = new AudioPlayer();
ap.play("mp3", "1");
ap.play("mp4", "2");
ap.play("vlc", "3");
ap.play("cd", "4");
}
}