-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapterMediaPlayer.java
More file actions
40 lines (31 loc) · 985 Bytes
/
AdapterMediaPlayer.java
File metadata and controls
40 lines (31 loc) · 985 Bytes
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
package design.Adapter;
public class AdapterMediaPlayer implements MediaPlayer{
public AdvancedPlayer player;
public AdapterMediaPlayer(String type) {
// TODO Auto-generated constructor stub
if("MP3".equalsIgnoreCase(type)) {
player = new Mp3Player();
} else if("MP4".equalsIgnoreCase(type)) {
player = new Mp4Player();
} else {
player = new AdvancedPlayer() {
public void playVideo(String filePath) {
// TODO Auto-generated method stub
System.out.println("AdvancedPlayer do nothing");
}
public void playAudio(String filePath) {
// TODO Auto-generated method stub
System.out.println("AdvancedPlayer do nothing");
}
};
}
}
public void play(String type, String filePath) {
// TODO Auto-generated method stub
if("Mp3".equalsIgnoreCase(type)) {
player.playAudio(filePath);
} else if("Mp4".equalsIgnoreCase(type)) {
player.playVideo(filePath);
}
}
}